WPF Image change source when button is disabled
Posted
by Taylor
on Stack Overflow
See other posts from Stack Overflow
or by Taylor
Published on 2010-05-14T01:41:22Z
Indexed on
2010/05/14
1:44 UTC
Read the original article
Hit count: 412
Hi, I'm trying to show a different image when the button is disabled. Should be easy with triggers, right?!
For some reason, I have not been able to get the images to switch. I've tried setting triggers on both the image and button. What is wrong with what I have below? How can I change the image source when the button is enabled/disabled?
Thanks!
<Button
x:Name="rleft"
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=rleft, 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>
© Stack Overflow or respective owner