How do I change the image when the button is disabled?

前端 未结 1 1558
暗喜
暗喜 2021-01-02 01:48

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

相关标签:
1条回答
  • 2021-01-02 01:58

    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>
    
    0 讨论(0)
提交回复
热议问题