如何使WPF图像无法使用?

Osk*_*kar 3 c# wpf xaml image

我需要一个在禁用时灰显的图像(IsEnabled = False).通过将BitmapImage读入此处显示的FormatConvertedBitmap,可以生成图像的灰色版本.

我已经能够使用UserControl,但现在我想在专门的Image类中使用相同的行为以获得更大的灵活性.我不在乎这是在XAML,代码隐藏还是两者中实现,但它需要是Image的子类.

用法可能是:

<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>
Run Code Online (Sandbox Code Playgroud)

Tho*_*que 10

看看这个链接

编辑:或者这一个(你需要的只是AutoGreyableImage类)


Fre*_*lad 5

我根据以下解决方案进行了一些比较.

由于我已经获得了WPF Infragistics Net Advantage的许可证,因此很容易尝试

这是结果

在此输入图像描述

所以最好的方法取决于你所追求的结果.至于我,我认为AutoDisabledImageInfragistics 产生的结果太亮了,AutoGreyableImage做得非常好(与方法1(OP链接)相同的结果)GreyscaleEffect产生最好的结果.