アイコンが付いたボタンがあり、無効にするとアイコンの色もグレー表示になります。私はスタイルトリガーを使用していくつかの異なる方法を疲れましたが、私はそれを働かせることはできません。私はWPFスタイリングには全く新しいので、どんな助けでも大歓迎です。ありがとうございました。WPFスタイルネストされた子要素のスタイルを更新するためのトリガー
ボタンコード:私は使用しています
<Button x:Name="btnNewProperty" Click="btnNewProperty_Click" Style="{StaticResource iconButton}" Width="145">
<StackPanel>
<Viewbox>
<Path Data="M17,13H13V17H11V13H7V11H11V7H13V11H17M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z" />
</Viewbox>
<TextBlock>New Property</TextBlock>
</StackPanel>
</Button>
スタイル:
<Application.Resources>
<SolidColorBrush x:Key="IconColor" Color="#FF444444" />
<SolidColorBrush x:Key="DisabledIconColor" Color="#FF999999" />
<Style x:Key="iconButton" TargetType="{x:Type Button}">
<Setter Property="Margin" Value="5,5,5,5" />
<Setter Property="Width" Value="120" />
<Setter Property="Height" Value="25" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Path">
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Value="{StaticResource DisabledIconColor}" Property="Fill" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<Style TargetType="{x:Type StackPanel}">
<Setter Property="Orientation" Value="Horizontal" />
</Style>
<Style TargetType="{x:Type Viewbox}">
<Setter Property="Width" Value="16" />
<Setter Property="Height" Value="16" />
</Style>
<Style TargetType="{x:Type Path}">
<Setter Property="Margin" Value="-2,-4,0,0" />
<Setter Property="Fill" Value="{StaticResource IconColor}" />
</Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Margin" Value="5,-2,0,0" />
<Setter Property="Padding" Value="0,0,0,0" />
</Style>
</Style.Resources>
</Style>
</Application.Resources>