Add GradientStops support to GradientBrush

This commit is contained in:
Oleksandr Liakhevych 2021-07-27 14:11:58 +03:00 коммит произвёл Eilon Lipton
Родитель 2e98968a99
Коммит 9976e74105
2 изменённых файлов: 66 добавлений и 0 удалений

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -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);
}
}
}