В стиле 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"];
Для полного изменения стиля вы можете обратиться к здесь .