开发者

WPF ContentControl : how to change control opacity in disabled mode in .cs file?

开发者 https://www.devze.com 2022-12-18 23:23 出处:网络
I have public class MyControl : ContentControl in wchich i have definitions of control and events correspondi开发者_运维知识库ng with it.

I have public class MyControl : ContentControl in wchich i have definitions of control and events correspondi开发者_运维知识库ng with it.

This control works fine, but when is disabled it looks still like enabled. I would like to do something like if control.isenabled = false then control.opacity = 0.5; How can i do it?


In WPF for such things triggers are used.

<MyControl>
<MyControl.Triggers>
   <Trigger Property="IsEnabled" Value="false">
       <Setter Property="Opacity" Value="0.5" />
   </Trigger>
</MyControl.Triggers>
</MyControl>


As you said - this trigger don't work - I have checked...

But I have found solution - in OnApplyTemplate method I have added few lines:

public override void OnApplyTemplate()
{
    //...
    if (this.IsEnabled == false)
    {
        this.Opacity = 0.4;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消