I make 'iconed button': Button and two TextBlock above (inside DockPanel). One TextBlock is 'icon' (w Awesome font), another is for text on button. Problem: when in VS designer I set IsEnabled=false, only second TextBlock become disabled - icon still has original color (no "disabled" look). WHY??
Unfortunately in clumsy C# you can override only what author allowed, so I had to create new 'IsEnabled' property:
public new bool IsEnabled
{
get => base.IsEnabled;
set {
base.IsEnabled = value;
txtIcon.Opacity = (value ? 1.0 : 0.4);
}
}
But again if in XAML I set IsEnabled=false, icon doesn't become disabled. And only when in code I set btnOK.IsEnabled=false, a whole button has disabled look.
I completely lost in this clumsy behaviour - even when I force button to make "disabled look" for icon, it's still misbehaves in VS designer (does designer set some another 'IsEnabled'??).
Any ideas? (ideally if I don't need to override 'IsEnabled')
SOLUTION
It seems if you set Foreground for a TextBlock, WPF check it and does nothing to make it look disabled (again WHY??). So you have to manually change appearance of your TextBlock. Best approach is to set Opacity property of TextBlock to smth like 0.3 if parent Button is disabled:
var b = new Binding {
// ElementName = "btnOK",
Source = btnOK,
Path = new PropertyPath("IsEnabled"),
};
b.Converter = new OpacityConv();// converts bool to 1.0 or 0.3
txtIcon.SetBinding(TextBlock.OpacityProperty, b);
If you change your approach to:
Xaml:
But even if it doesn't work, you can always change the colour of the text!
Workaround