问题
As NumBox
seems to have a bug of not dimming the label when the control is disabled (other controls do, of course), I try to style it to force this behavior:
<Style TargetType="ux:NumberBox">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock x:Name="HeaderText" Text="{Binding}" Foreground="{ThemeResource TextControlHeaderForeground}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Target="HeaderText.Foreground" Value="{ThemeResource SystemControlDisabledBaseMediumLowBrush}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
While the original Foreground
is OK, it doesn't pick up the change in the visual state and the label stays the same color. What am I doing wrong?
回答1:
While the original Foreground is OK, it doesn't pick up the change in the visual state and the label stays the same color. What am I doing wrong?
The problem is TextBlock
does not contains Disabled
state. So it will not work.
Disabled color of NumBox header
It's know issue for NumberBox, and it is fixed in latest version, please try to install 2.5.0-prerelease with following command.
Install-Package Microsoft.UI.Xaml -Version 2.5.0-prerelease.201027002
来源:https://stackoverflow.com/questions/65073268/disabled-color-of-numbox-header