我如何改变形象,当按钮被禁用? [英] How do I change the image when the button is disabled?

查看:148
本文介绍了我如何改变形象,当按钮被禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想表现出不同的图像时,该按钮被禁用;我认为这将是容易触发。

不过,我一直没能得到图像源当按钮被禁用切换到残疾人的形象。我试过设置图像和按钮上都触发器。有什么不对我有什么下文?我怎样才能改变图像源当按钮被启用/禁用?

 <按钮
         X:NAME =btnN​​ame
         命令={绑定路径=操作}
         CommandParameter ={X:静态VM:Ops.OpA}>
            < Button.Content>
                <&StackPanel的GT;
                    <图像
                  WIDTH =24
                  身高=24
                  RenderOptions.BitmapScalingMode =最近邻
                  SnapsToDevicePixels =真
                  来源=/ MyAssembly程序,组件/图像/ enabled.png>
                        < Image.Style>
                            <样式和GT;
                                < Style.Triggers>
                                    < D​​ataTrigger绑定={绑定的ElementName = btnName,路径= Button.IsEnabled}VALUE =FALSE>
                                        < setter属性=Image.SourceVALUE =/ MyAssembly程序,组件/图像/ disabled.png/>
                                    < / DataTrigger>
                                < /Style.Triggers>
                            < /样式和GT;
                        < /Image.Style>
                    < /图像>
                < / StackPanel的>
            < /Button.Content>
        < /按钮>


解决方案

呀这一个弹出不少。

这是明确的对象的声明中设置的任何属性不能在风格改变。所以,因为你已经设置图像的来源属性在图像的声明,该样式的二传手不会动它。

试试这个:

 <图像
    WIDTH =24
    身高=24
    RenderOptions.BitmapScalingMode =最近邻
    SnapsToDevicePixels =真
    >
    < Image.Style>
        <风格的TargetType =图片>
            < setter属性=源
                    VALUE =/ MyAssembly程序,组件/图像/ enabled.png/>
            < Style.Triggers>
                ...您的触发和setter ...
            < /Style.Triggers>
        < /样式和GT;
    < /Image.Style>
< /图像>

I'm trying to show a different image when the button is disabled; I thought it would be easy with triggers.

However, I have not been able to get the image source to switch to the disabled image when the button is disabled. I've tried setting triggers on both the image and button. What is wrong with what I have below? How can I change the image source when the button is enabled/disabled?

<Button
         x:Name="btnName"
         Command="{Binding Path=Operation}"
         CommandParameter="{x:Static vm:Ops.OpA}">
            <Button.Content>
                <StackPanel>
                    <Image
                  Width="24"
                  Height="24"             
                  RenderOptions.BitmapScalingMode="NearestNeighbor"
                  SnapsToDevicePixels="True"
                  Source="/MyAssembly;component/images/enabled.png">
                        <Image.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding ElementName=btnName, Path=Button.IsEnabled}" Value="False">
                                        <Setter Property="Image.Source" Value="/MyAssembly;component/images/disabled.png" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                    </Image>
                </StackPanel>
            </Button.Content>
        </Button>

解决方案

Yeah this one pops up quite a bit.

Any property that's explicitly set in the object's declaration can't be changed in a style. So because you've set the image's Source property in the declaration of the image, the style's Setter won't touch it.

Try this instead:

<Image
    Width="24"  
    Height="24"               
    RenderOptions.BitmapScalingMode="NearestNeighbor"  
    SnapsToDevicePixels="True"
    >
    <Image.Style>
        <Style TargetType="Image">
            <Setter Property="Source"
                    Value="/MyAssembly;component/images/enabled.png" />
            <Style.Triggers>
                ... your trigger and setter ...
            </Style.Triggers>
        </Style>
    </Image.Style>
</Image>

这篇关于我如何改变形象,当按钮被禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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