Refactor IconProvider default value set bug

This commit is contained in:
chinboy
2025-11-25 16:27:34 +08:00
parent 8a2699307a
commit 897aff5d12
4 changed files with 21 additions and 17 deletions
@@ -1,5 +1,4 @@
using System.Diagnostics;
using Avalonia.Layout;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
@@ -45,39 +44,39 @@ public abstract class IconProvider<TIconKind> : MarkupExtension
if (NormalFilledColor != null)
{
icon.SetCurrentValue(Icon.NormalFilledBrushProperty, NormalFilledColor);
icon.NormalFilledBrush = NormalFilledColor;
}
if (ActiveFilledColor != null)
{
icon.SetCurrentValue(Icon.ActiveFilledBrushProperty, ActiveFilledColor);
icon.ActiveFilledBrush = ActiveFilledColor;
}
if (SelectedFilledColor != null)
{
icon.SetCurrentValue(Icon.SelectedFilledBrushProperty, SelectedFilledColor);
icon.SelectedFilledBrush = SelectedFilledColor;
}
if (DisabledFilledColor != null)
{
icon.SetCurrentValue(Icon.DisabledFilledBrushProperty, DisabledFilledColor);
icon.DisabledFilledBrush = DisabledFilledColor;
}
if (PrimaryFilledColor != null)
{
icon.SetCurrentValue(Icon.PrimaryFilledBrushProperty, PrimaryFilledColor);
icon.PrimaryFilledBrush = PrimaryFilledColor;
}
if (SecondaryFilledColor != null)
{
icon.SetCurrentValue(Icon.SecondaryFilledBrushProperty, SecondaryFilledColor);
icon.SecondaryFilledBrush = SecondaryFilledColor;
}
if (!double.IsNaN(Width))
{
icon.SetCurrentValue(Layoutable.WidthProperty, Width);
icon.Width = Width;
}
if (!double.IsNaN(Height))
{
icon.SetCurrentValue(Layoutable.HeightProperty, Height);
icon.Height = Height;
}
return icon;
@@ -49,7 +49,7 @@
Value="{DynamicResource {x:Static atom:SharedTokenKey.IconSizeSM}}" />
</Style>
</Style>
<Setter Property="NormalFilledBrush"
Value="{DynamicResource {x:Static atom:SharedTokenKey.ColorTextTertiary}}" />
<Setter Property="PrimaryFilledBrush"
@@ -264,9 +264,11 @@ public class SpinIndicator : TemplatedControl,
{
var middleStyle = new Style(x =>
x.PropertyEquals(SizeTypeProperty, SizeType.Middle));
var iconStyle = new Style(x =>
var iconStyle = new Style(x => Selectors.Or(
x.Nesting().Descendant().OfType<ContentPresenter>().Name(SpinThemeConstants.CustomIndicatorPresenterPart).Child()
.OfType<PathIcon>());
.OfType<PathIcon>(),
x.Nesting().Descendant().OfType<ContentPresenter>().Name(SpinThemeConstants.CustomIndicatorPresenterPart).Child()
.OfType<Icon>()));
iconStyle.Add(WidthProperty, SpinTokenKey.IndicatorSize);
iconStyle.Add(HeightProperty, SpinTokenKey.IndicatorSize);
middleStyle.Add(iconStyle);
@@ -275,9 +277,11 @@ public class SpinIndicator : TemplatedControl,
{
var smallStyle = new Style(x =>
x.PropertyEquals(SizeTypeProperty, SizeType.Small));
var iconStyle = new Style(x =>
var iconStyle = new Style(x => Selectors.Or(
x.Nesting().Descendant().OfType<ContentPresenter>().Name(SpinThemeConstants.CustomIndicatorPresenterPart).Child()
.OfType<PathIcon>());
.OfType<PathIcon>(),
x.Nesting().Descendant().OfType<ContentPresenter>().Name(SpinThemeConstants.CustomIndicatorPresenterPart).Child()
.OfType<Icon>()));
iconStyle.Add(WidthProperty, SpinTokenKey.IndicatorSizeSM);
iconStyle.Add(HeightProperty, SpinTokenKey.IndicatorSizeSM);
smallStyle.Add(iconStyle);
@@ -286,9 +290,11 @@ public class SpinIndicator : TemplatedControl,
{
var largeStyle = new Style(x =>
x.PropertyEquals(SizeTypeProperty, SizeType.Large));
var iconStyle = new Style(x =>
var iconStyle = new Style(x => Selectors.Or(
x.Nesting().Descendant().OfType<ContentPresenter>().Name(SpinThemeConstants.CustomIndicatorPresenterPart).Child()
.OfType<PathIcon>());
.OfType<PathIcon>(),
x.Nesting().Descendant().OfType<ContentPresenter>().Name(SpinThemeConstants.CustomIndicatorPresenterPart).Child()
.OfType<Icon>()));
iconStyle.Add(WidthProperty, SpinTokenKey.IndicatorSizeLG);
iconStyle.Add(HeightProperty, SpinTokenKey.IndicatorSizeLG);
largeStyle.Add(iconStyle);
@@ -1,7 +1,6 @@
using System.Diagnostics;
using System.Reflection;
using AtomUI.Controls;
using AtomUI.Icons.AntDesign;
namespace AtomUI.Icons.AntDesign;