我怎样才能让一个WPF图像disableable? [英] How can I make a WPF Image disableable?

查看:107
本文介绍了我怎样才能让一个WPF图像disableable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要禁用(IsEnabled = FALSE)时显示为灰色图像。图像的灰色显示的版本可以通过读取的BitmapImage成被出示一张FormatConvertedBitmap的这里



我已经能够得到一个用户控件这方面的工作,但现在的我想同样的行为在一个专门的Image类有更多的灵活性。如果这是在XAML实现我不在乎,代码隐藏或两者兼而有之,但它需要图像的子类



用法可能是:

 < D​​isableableImage源=图像/ image1.png/> 
< D​​isableableImage源=图像/ image1.pngIsEnabled =FALSE/>

<! - 由于IsEnabled被继承了下来树,
图像将被Like按钮的其余部分变灰 - >
<按钮IsEnabled =FALSE>
< StackPanel的方向=横向>
<&的TextBlock GT;确定< / TextBlock的>
< D​​isableableImage源=图像/ 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆