I’m having trouble binding the label color on my Microsoft.Windows.Controls.Ribbon.RibbonTab objects to their Enabled state.
I tried the following first:
<Style TargetType="{x:Type r:RibbonTab}">
<Setter Property="Foreground" Value="White" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsEnabled}" Value="False">
<Setter Property="Foreground" Value="Gray" />
</DataTrigger>
</Style.Triggers>
</Style>
But it has no affect on the foreground. It looks like something in the ribbonTab library code is programatically overwriting the foreground.
I then tried this:
<Style x:Key="BaseRibbonTabStyle" TargetType="{x:Type r:RibbonTab}">
<EventSetter Event="IsEnabledChanged" Handler="RibbonTab_IsEnabledChanged"
</Style>
private void RibbonTab_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if( (bool)e.NewValue == false )
((RibbonTab)sender).Foreground = (new System.Windows.Media.BrushConverter()).ConvertFromString("Gray") as System.Windows.Media.Brush;
else
((RibbonTab)sender).Foreground = (new System.Windows.Media.BrushConverter()).ConvertFromString("White") as System.Windows.Media.Brush;
}
But that also failed with the following compile time error:
System.Windows.UIElement.IsEnabledChanged="RibbonTab_IsEnabledChanged_Event" is not valid. 'IsEnabledChanged' must be a RoutedEvent registered with a name that ends with the keyword "Event".
How can I get this to work?
Try a simple property trigger: