In .NET Maui I have this XAML:
<Style x:Key="GreenLabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="Green"/>
</Style>
<Label Style="{StaticResource GreenLabelStyle}"
Text="Some text"
TextColor="{Binding SometimesOverrideColor}"
/>
<CheckBox IsChecked="{Binding OverrideColorStyle}"/>
The Label’s TextColor is bound to this property:
public Color SometimesOverrideColor
{
get
{
return OverrideColorStyle ? Colors.Pink : Colors.Green; // works, but not DRY
}
}
Even though I have a specified a (bound) TextColor
, I want the option to say “ignore this property setting and act as though there were no explicit TextColor on the Label”. I tried returning null
for SometimesOverrideColor
, but that didn’t work. I want to use the value of the Label’s style (i.e. green).
Obviously, I can return Colors.Green
in SometimesOverrideColor
, but that repeats the value specified in the style. If I changed the style I would have to remember to update the property.
What I have in mind is like the inherit
keyword in CSS. If I could return Color.Inherit
that would be great!