tags:

views:

603

answers:

3

I need an Image that is grayed out when disabled (IsEnabled=False). A grayed out version of the image can be produced by reading the BitmapImage into a FormatConvertedBitmap which is shown here.

I have been able to get this working with a UserControl but now I would like the same behavior in a specialized Image class for more flexibility. I don't care if this is implemented in XAML, code-behind or both, but it needs to be a subclass of Image.

The usage could be:

<DisableableImage Source="Images/image1.png" />
<DisableableImage Source="Images/image1.png" IsEnabled="False" />

<!-- Since IsEnabled is inherited down the tree,
     the image will be grayed out like the rest of the button -->
<Button IsEnabled="False">
    <StackPanel Orientation="Horizontal">
        <TextBlock>OK</TextBlock>
        <DisableableImage Source="Images/ok.png" />
    </StackPanel>
</Button>
+3  A: 

Have a look at this link

EDIT: Or this one (it's in French, but all you need is the AutoGreyableImage class)

Thomas Levesque
Thanks! But I'm not ready to buy the whole Infragistics Win Client package for this class only :)
Oskar
Sorry, I didn't realize it was an Infragistics control... I have another link, I'll update my answer
Thomas Levesque
Thanks again, the solution in the new link works great!
Oskar
A: 

Create a DisableableImage class that is a typical WPF control. Inside, place two elements: the image, and a rectangle that appears only when the control is disabled. The rectangle should be the same width and height as the image, and it should overlay the image. With a color of gray and an alpha of somewhere around 40%, you should get an effect similar to actually graying out the image -- without all the effort to actually modify the image itself.

John Fisher
It's a nice idea, but if you try it, it looks nothing like the effect the questoner's trying to achieve. It just looks like a semi-transparent gray rectangle over an image. :)
Mal Ross
I guess that depends on exactly what someone means by "grayed out", but yes, there would be a little color left.
John Fisher
+1  A: 

if you use this a lot consider creating a custom Effect introduced with .NET 3.5 SP1 (not bitmapeffect) to render such an operation on your GPU. this effect can then be easily controlled by triggers.

Joachim Kerschbaumer