问题描述
我需要禁用(IsEnabled = FALSE)时显示为灰色图像。图像的灰色显示的版本可以通过读取的BitmapImage成被出示一张FormatConvertedBitmap的。
我已经能够得到一个用户控件这方面的工作,但现在的我想同样的行为在一个专门的Image类有更多的灵活性。如果这是在XAML实现我不在乎,代码隐藏或两者兼而有之,但它需要图像的子类
用法可能是:
< DisableableImage源=图像/ image1.png/>
< DisableableImage源=图像/ image1.pngIsEnabled =FALSE/>
<! - 由于IsEnabled被继承了下来树,
图像将被Like按钮的其余部分变灰 - >
<按钮IsEnabled =FALSE>
< StackPanel的方向=横向>
<&的TextBlock GT;确定< / TextBlock的>
< DisableableImage源=图像/ ok.png/>
< / StackPanel的>
< /按钮>
有一个看的
编辑:
或的(所有你需要的是AutoGreyableImage类)
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>
Have a look at this link
EDIT:Or this one (all you need is the AutoGreyableImage class)
这篇关于我怎样才能让一个WPF图像disableable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!