Фон AppBarButton Не будет изменен, если он отключен в UWP? - PullRequest
0 голосов
/ 01 апреля 2020
AppBarButton AppBarButton = new AppBarButton();
AppBarButton.Label = "Pictures";
AppBarButton.IsEnabled = false;
AppBarButton.Background = new SolidColorBrush(Colors.LightGray);

Когда AppBarButton IsEnabled = false. Я не могу установить фон для Appbarbutton, и он выглядит прозрачным .... Как установить цвет LightGray, когда IsEnabled = false в UWP?

1 Ответ

1 голос
/ 02 апреля 2020

В стиле AppBarButton по умолчанию существует состояние " Отключено ". Когда вы отключите AppBarButton, вступит в силу состояние «Отключено». В качестве фона Root установлено значение {ThemeResource AppBarButtonBackgroundDisabled}, поэтому вы не установили фон успешно. Таким образом, вы можете удалить эту строку и применить новый стиль для AppBarButton, фон изменится.

.xaml:

Строка под комментарием вызывает прозрачный фон, вы можете оставить комментарий или удалить его .

<VisualState x:Name="Disabled">
    <VisualState.Setters>
        <!--<Setter Target="Root.Background" Value="{ThemeResource AppBarButtonBackgroundDisabled}"/>-->
        <Setter Target="Root.BorderBrush" Value="{ThemeResource AppBarButtonBorderBrushDisabled}"/>
        <Setter Target="AppBarButtonInnerBorder.Stroke" Value="{ThemeResource AppBarButtonBorderBrushDisabled}"/>
        <Setter Target="Content.Foreground" Value="{ThemeResource AppBarButtonForegroundDisabled}"/>
        <Setter Target="TextLabel.Foreground" Value="{ThemeResource AppBarButtonForegroundDisabled}"/>
        <Setter Target="OverflowTextLabel.Foreground" Value="{ThemeResource AppBarButtonForegroundDisabled}"/>
        <Setter Target="KeyboardAcceleratorTextLabel.Foreground" Value="{ThemeResource AppBarButtonKeyboardAcceleratorTextForegroundDisabled}"/>
    </VisualState.Setters>
</VisualState>

.cs:

AppBarButton AppBarButton = new AppBarButton();
AppBarButton.Label = "Pictures";
AppBarButton.IsEnabled = false;
AppBarButton.Background = new SolidColorBrush(Colors.Red);
AppBarButton.Style = (Style)this.Resources["AppBarButtonStyle1"];

Для полного изменения стиля вы можете обратиться к здесь .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...