Files
Shrlalgo.RvKits/NeuWPF/NeoUI/Controls/SymbolIcon.xaml
2025-08-20 12:10:13 +08:00

73 lines
3.8 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:NeumUI.Controls"
xmlns:conv="clr-namespace:NeumUI.Converters"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- 确保字体资源路径正确 -->
<FontFamily x:Key="MaterialIconFont">pack://application:,,,/NeumUI;component/Assets/#Material Symbols Rounded</FontFamily>
<Style TargetType="{x:Type controls:SymbolIcon}" x:Key="SymbolIconStyle">
<!-- 为控件设置默认值 -->
<Setter Property="FontFamily" Value="{StaticResource MaterialIconFont}" />
<Setter Property="FontSize" Value="16" />
<!--<Setter Property="IsHitTestVisible" Value="False"/>-->
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Focusable" Value="False" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<!-- 核心部分:定义控件模板 -->
<!-- 使用 TemplateBinding 将 SymbolIcon 的属性应用到内部 TextBlock -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:SymbolIcon}">
<Border Background="Transparent">
<!-- ==================== 新增部分 ==================== -->
<!--<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<Storyboard>
-->
<!-- 目标是模板内的 IconText 元素 -->
<!--
<DoubleAnimation Duration="0:0:0.1"
Storyboard.TargetName="IconText"
Storyboard.TargetProperty="Opacity"
To="0.5" />
-->
<!-- 0.1秒的过渡动画 -->
<!--
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>-->
<!-- ================================================= -->
<TextBlock
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Text="{Binding Symbol, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static conv:SymbolToCharConverter.Instance}}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="IconText" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- 当控件的 IsEnabled 属性为 False 时 -->
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
</Trigger>
</Style.Triggers>
</Style>
<Style BasedOn="{StaticResource SymbolIconStyle}" TargetType="controls:SymbolIcon" />
</ResourceDictionary>