I am very new to wpf and the problem as follows.
Buttons with images should really behave like those in WinForms - grayed out when disabled (so as some suggest setting opacity for an image isn't enough because it leaves colors).
So I found piece of code:
<Image RenderOptions.BitmapScalingMode="NearestNeighbor" Height="20" Width="20"
Opacity="{Binding SelectedItem, Converter={StaticResource selectedItemPresent}}">
<Image.Source>
<FormatConvertedBitmap DestinationFormat="Gray8">
<FormatConvertedBitmap.Source>
<BitmapImage UriSource="Images/edit_info.png" />
</FormatConvertedBitmap.Source>
</FormatConvertedBitmap>
</Image.Source>
<Image.OpacityMask>
<ImageBrush>
<ImageBrush.ImageSource>
<BitmapImage UriSource="Images/edit_info.png">
</ImageBrush.ImageSource>
</ImageBrush>
</Image.OpacityMask>
</Image>
This yields a grayed out button and the job is half done. (Converter just returns either 1 or 0.3 based on databound item value.)
However what I really need is to gray it out only when selected item is null.
So, I have two questions. 1.How to apply all that ... stuff based on a data context value? May be create another converter. Then I'll have to do this declarative xaml programmatically? Or I can define some rule in xaml, so part will be valid only when the rule fires?
2.This should be done to several buttons - how can this logic can be factored out (I saw some style.xaml in relevant project - is that where to put it)?
Thanks for consideration.