Disable a toolbar button image in WPF
When I worked with winforms, it was very easy to disable a toolbar button image, just set Enabled=False and your were done. With WPF on the other hand, it is a little bit more complicated.
I love WPF! You can do everything you couldn’t to in winforms. You have total control. But the downside of having total control is that you must control everything. :-)
So, to disable a toolbar button with an image, which I do via application commands, use this following trigger.
<Style TargetType="{x:Type Image}" x:Key="toolbarImageStyle"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}, AncestorLevel=1}, Path=IsEnabled}" Value="False"> <Setter Property="Opacity" Value="0.50"></Setter> </DataTrigger> </Style.Triggers> </Style>
And in the toolbar apply the style.
<Button Name="btPlayersDelete" Command="commands:UserCommands.DeleteUsers" ToolTip="Delete players"> <Image Style="{StaticResource toolbarImageStyle}" Name="imgPlayersDelete"
Source="Images/Toolbar/delete.png"/> </Button>

1 Comments:
Exactly what I was looking for,
Thank you!
Post a Comment
Links to this post:
Create a Link
<< Home