【发布时间】:2011-02-19 08:32:19
【问题描述】:
当按钮被禁用时,我试图显示不同的图像;我认为使用触发器会很容易。
但是,当按钮被禁用时,我无法让图像源切换到禁用的图像。我尝试在图像和按钮上设置触发器。我在下面有什么问题?启用/禁用按钮时如何更改图像源?
<Button
x:Name="btnName"
Command="{Binding Path=Operation}"
CommandParameter="{x:Static vm:Ops.OpA}">
<Button.Content>
<StackPanel>
<Image
Width="24"
Height="24"
RenderOptions.BitmapScalingMode="NearestNeighbor"
SnapsToDevicePixels="True"
Source="/MyAssembly;component/images/enabled.png">
<Image.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=btnName, Path=Button.IsEnabled}" Value="False">
<Setter Property="Image.Source" Value="/MyAssembly;component/images/disabled.png" />
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</StackPanel>
</Button.Content>
</Button>
【问题讨论】: