Warm tip: This article is reproduced from serverfault.com, please click

Disabled color of NumBox header

发布于 2020-11-30 12:06:15

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?

Questioner
Gábor
Viewed
0
Nico Zhu - MSFT 2020-11-30 22:00:39

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