给定以下具有自定义内容的 WPF 按钮,如何使用触发器在启用按钮时将其标签的前景颜色更改为蓝色,在禁用按钮时更改为红色?
<Window x:Class="CustomButtonTriggerExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Button IsEnabled="{Binding ElementName=chkEnabled, Path=IsChecked}">
<StackPanel Orientation="Horizontal">
<Label VerticalContentAlignment="Center">This is a label control inside a button</Label>
<Image Height="50" Width="50" Source="/CustomButtonTriggerExample;component/Images/Some Image.png" Stretch="Fill" />
</StackPanel>
</Button>
<CheckBox x:Name="chkEnabled">Button Enabled</CheckBox>
</StackPanel>
</Grid>
</Window>