-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GradientStops support to GradientBrush
- Loading branch information
1 parent
2e98968
commit 9976e74
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/Microsoft.MobileBlazorBindings/Elements/GradientBrush.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Microsoft.MobileBlazorBindings.Elements | ||
{ | ||
public abstract partial class GradientBrush : Brush | ||
{ | ||
#pragma warning disable CA1721 // Property names should not match get methods | ||
[Parameter] public RenderFragment ChildContent { get; set; } | ||
#pragma warning restore CA1721 // Property names should not match get methods | ||
|
||
protected override RenderFragment GetChildContent() => ChildContent; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Microsoft.MobileBlazorBindings/Elements/Handlers/GradientBrushHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using XF = Xamarin.Forms; | ||
|
||
namespace Microsoft.MobileBlazorBindings.Elements.Handlers | ||
{ | ||
public abstract partial class GradientBrushHandler : BrushHandler, IXamarinFormsContainerElementHandler | ||
{ | ||
public void AddChild(XF.Element child, int physicalSiblingIndex) | ||
{ | ||
if (!(child is XF.GradientStop gradientStopChild)) | ||
{ | ||
throw new ArgumentException($"GradientBrush support GradientStop child elements only, but {child?.GetType()} found instead.", nameof(child)); | ||
} | ||
|
||
if (physicalSiblingIndex <= GradientBrushControl.GradientStops.Count) | ||
{ | ||
GradientBrushControl.GradientStops.Insert(physicalSiblingIndex, gradientStopChild); | ||
} | ||
else | ||
{ | ||
Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but GradientBrushControl.GradientStops.Count={GradientBrushControl.GradientStops}"); | ||
GradientBrushControl.GradientStops.Add(gradientStopChild); | ||
} | ||
} | ||
|
||
public int GetChildIndex(XF.Element child) | ||
{ | ||
if (!(child is XF.GradientStop gradientStopChild)) | ||
{ | ||
throw new ArgumentException($"GradientBrush support GradientStop child elements only, but {child?.GetType()} found instead.", nameof(child)); | ||
} | ||
|
||
return GradientBrushControl.GradientStops.IndexOf(gradientStopChild); | ||
} | ||
|
||
public void RemoveChild(XF.Element child) | ||
{ | ||
if (!(child is XF.GradientStop gradientStopChild)) | ||
{ | ||
throw new ArgumentException($"GradientBrush support GradientStop child elements only, but {child?.GetType()} found instead.", nameof(child)); | ||
} | ||
|
||
GradientBrushControl.GradientStops.Remove(gradientStopChild); | ||
} | ||
} | ||
} |