Saturday, 10 January 2009

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">
Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}, 
AncestorLevel=1}, Path=IsEnabled}" Value="False">
                    <Setter Property="Opacity" Value="0.50"></Setter>

And in the toolbar apply the style.

ToolTip="Delete players">
             Style="{StaticResource toolbarImageStyle}" 
Source="Images/Toolbar/delete.png"/> </Button>

Labels: ,

kick it on


Anonymous Mona said...

Exactly what I was looking for,

Thank you!

16 April 2010 16:06  

Post a Comment

Links to this post:

Create a Link

<< Home