Reputation: 2947
I have public class MyControl : ContentControl
in wchich i have definitions of control and events corresponding 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?
Upvotes: 0
Views: 4579
Reputation: 2947
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;
}
}
Upvotes: 0
Reputation: 1699
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>
Upvotes: 1