fix: fix :checked:disabled color in AppBarToggleButton.

This commit is contained in:
Zhang Dian
2026-03-12 16:34:24 +08:00
parent dd5f5182fa
commit c84c8a3c90
5 changed files with 69 additions and 32 deletions

View File

@@ -8,37 +8,62 @@
d:DesignHeight="600"
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.Resources>
<collections:AvaloniaList x:TypeArguments="CommandBarDefaultLabelPosition" x:Key="LabelPositionList">
<CommandBarDefaultLabelPosition>Bottom</CommandBarDefaultLabelPosition>
<CommandBarDefaultLabelPosition>Collapsed</CommandBarDefaultLabelPosition>
<CommandBarDefaultLabelPosition>Right</CommandBarDefaultLabelPosition>
</collections:AvaloniaList>
<collections:AvaloniaList x:TypeArguments="CommandBarOverflowButtonVisibility" x:Key="VisibilityList">
<CommandBarOverflowButtonVisibility>Auto</CommandBarOverflowButtonVisibility>
<CommandBarOverflowButtonVisibility>Collapsed</CommandBarOverflowButtonVisibility>
<CommandBarOverflowButtonVisibility>Visible</CommandBarOverflowButtonVisibility>
</collections:AvaloniaList>
</UserControl.Resources>
<ScrollViewer>
<StackPanel Spacing="16">
<HeaderedContentControl Theme="{StaticResource GroupBox}">
<HeaderedContentControl.Header>
<StackPanel HorizontalAlignment="Left">
<TextBlock Text="CommandBar — Dynamic Overflow" />
<ComboBox
Name="lc"
ItemsSource="{DynamicResource LabelPositionList}"
SelectedValue="{x:Static CommandBarDefaultLabelPosition.Bottom}">
<ComboBox.Resources>
<collections:AvaloniaList x:TypeArguments="CommandBarDefaultLabelPosition" x:Key="LabelPositionList">
<CommandBarDefaultLabelPosition>Bottom</CommandBarDefaultLabelPosition>
<CommandBarDefaultLabelPosition>Collapsed</CommandBarDefaultLabelPosition>
<CommandBarDefaultLabelPosition>Right</CommandBarDefaultLabelPosition>
</collections:AvaloniaList>
</ComboBox.Resources>
</ComboBox>
<ToggleSwitch Name="idfe" IsChecked="True" />
<Slider Name="ws" Width="500" Minimum="0" Maximum="1000" Value="200" />
</StackPanel>
</HeaderedContentControl.Header>
<GroupBox>
<GroupBox.Header>
<Grid ColumnDefinitions="Auto,*" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto">
<TextBlock Grid.Row="0" Grid.Column="0" Text="DefaultLabelPosition" VerticalAlignment="Center" />
<ComboBox Grid.Row="0" Grid.Column="1"
Name="lc"
ItemsSource="{DynamicResource LabelPositionList}"
SelectedValue="{x:Static CommandBarDefaultLabelPosition.Bottom}" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="OverflowButtonVisibility" VerticalAlignment="Center" />
<ComboBox Grid.Row="1" Grid.Column="1"
Name="btvb"
ItemsSource="{DynamicResource VisibilityList}"
SelectedValue="{x:Static CommandBarOverflowButtonVisibility.Auto}" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="IsDynamicOverflowEnabled" VerticalAlignment="Center" />
<ToggleSwitch Grid.Row="2" Grid.Column="1" Name="idfe" IsChecked="True" />
<TextBlock Grid.Row="3" Grid.Column="0" Text="IsOpen" VerticalAlignment="Center" />
<ToggleSwitch Grid.Row="3" Grid.Column="1" Name="isop" />
<TextBlock Grid.Row="4" Grid.Column="0" Text="IsSticky" VerticalAlignment="Center" />
<ToggleSwitch Grid.Row="4" Grid.Column="1" Name="isst" />
<TextBlock Grid.Row="5" Grid.Column="0" Text="Width" VerticalAlignment="Center" />
<Slider Grid.Row="5" Grid.Column="1" Name="ws" HorizontalAlignment="Left" Width="500" Minimum="0" Maximum="1000" Value="200" />
</Grid>
</GroupBox.Header>
<CommandBar
DefaultLabelPosition="{Binding #lc.SelectedValue}"
OverflowButtonVisibility="{Binding #btvb.SelectedValue}"
IsDynamicOverflowEnabled="{Binding #idfe.IsChecked}"
Width="{Binding #ws.Value}"
DefaultLabelPosition="{Binding #lc.SelectedValue}">
IsOpen="{Binding #isop.IsChecked}"
IsSticky="{Binding #isst.IsChecked}"
Width="{Binding #ws.Value}">
<AppBarButton Label="New" Icon="{DynamicResource SemiIconPlus}" />
<AppBarButton Label="Save" Icon="{DynamicResource SemiIconSave}" />
<AppBarSeparator />
<AppBarToggleButton Label="Bold" Icon="{DynamicResource SemiIconBold}" />
<AppBarToggleButton Label="Italic" Icon="{DynamicResource SemiIconItalic}" />
<AppBarToggleButton IsChecked="True" IsEnabled="False" Label="Underline" Icon="{DynamicResource SemiIconUnderline}" />
<AppBarSeparator />
<AppBarButton Label="Share" Icon="{DynamicResource SemiIconShare}" />
<AppBarButton Label="Export" Icon="{DynamicResource SemiIconExport}" />
@@ -46,13 +71,13 @@
<AppBarSeparator />
<AppBarButton Label="Delete" Icon="{DynamicResource SemiIconDelete}" />
</CommandBar>
</HeaderedContentControl>
</GroupBox>
<!-- With secondary commands (overflow) -->
<HeaderedContentControl Theme="{StaticResource GroupBox}">
<HeaderedContentControl.Header>
<GroupBox>
<GroupBox.Header>
<TextBlock Text="CommandBar — With Secondary Commands (overflow)" />
</HeaderedContentControl.Header>
</GroupBox.Header>
<CommandBar>
<AppBarButton Label="New" Icon="{DynamicResource SemiIconPlus}" />
<AppBarButton Label="Save" Icon="{DynamicResource SemiIconSave}" />
@@ -62,7 +87,7 @@
<AppBarButton Label="Delete" Icon="{DynamicResource SemiIconDelete}" />
</CommandBar.SecondaryCommands>
</CommandBar>
</HeaderedContentControl>
</GroupBox>
</StackPanel>
</ScrollViewer>

View File

@@ -4,8 +4,8 @@
xmlns:collections="clr-namespace:Avalonia.Collections;assembly=Avalonia.Base">
<Design.PreviewWith>
<HeaderedContentControl Height="500" Theme="{StaticResource GroupBox}">
<HeaderedContentControl.Header>
<GroupBox Height="500">
<GroupBox.Header>
<StackPanel>
<ComboBox
Name="lc"
@@ -22,7 +22,7 @@
<ToggleSwitch Name="idfe" IsChecked="True" />
<Slider Name="ws" Width="500" Minimum="0" Maximum="500" Value="200" />
</StackPanel>
</HeaderedContentControl.Header>
</GroupBox.Header>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<CommandBar
DefaultLabelPosition="{Binding #lc.SelectedValue}"
@@ -33,7 +33,7 @@
<AppBarSeparator />
<AppBarToggleButton Label="Bold" Icon="{DynamicResource SemiIconBold}" />
<AppBarToggleButton Label="Italic" Icon="{DynamicResource SemiIconItalic}" />
<AppBarToggleButton Label="Underline" Icon="{DynamicResource SemiIconUnderline}" />
<AppBarToggleButton IsEnabled="False" IsChecked="True" Label="Underline" Icon="{DynamicResource SemiIconUnderline}" />
<AppBarSeparator />
<AppBarButton Label="Share" Icon="{DynamicResource SemiIconShare}" />
<AppBarButton Label="Export" Icon="{DynamicResource SemiIconExport}" />
@@ -42,7 +42,7 @@
<AppBarButton Label="Delete" Icon="{DynamicResource SemiIconDelete}" />
</CommandBar>
</StackPanel>
</HeaderedContentControl>
</GroupBox>
</Design.PreviewWith>
<ControlTheme x:Key="AppBarButtonBaseTheme" TargetType="Button">
@@ -197,6 +197,12 @@
<Style Selector="^:pointerover /template/ Border#PART_Border">
<Setter Property="Background" Value="{DynamicResource AppBarToggleButtonCheckedPointeroverBackground}" />
</Style>
<Style Selector="^:pressed /template/ Border#PART_Border">
<Setter Property="Background" Value="{DynamicResource AppBarToggleButtonCheckedPressedBackground}" />
</Style>
<Style Selector="^:disabled /template/ ContentPresenter#PART_IconPresenter">
<Setter Property="Foreground" Value="{DynamicResource AppBarToggleButtonCheckedDisabledForeground}" />
</Style>
</Style>
<!-- IsCompact: hide label, use compact width -->

View File

@@ -9,6 +9,8 @@
<StaticResource x:Key="AppBarToggleButtonCheckedForeground" ResourceKey="SemiColorPrimary" />
<StaticResource x:Key="AppBarToggleButtonCheckedBackground" ResourceKey="SemiColorPrimaryLight" />
<StaticResource x:Key="AppBarToggleButtonCheckedPointeroverBackground" ResourceKey="SemiColorPrimaryLightPointerover" />
<StaticResource x:Key="AppBarToggleButtonCheckedPressedBackground" ResourceKey="SemiColorPrimaryLightActive" />
<StaticResource x:Key="AppBarToggleButtonCheckedDisabledForeground" ResourceKey="SemiColorPrimaryDisabled" />
<!-- AppBarSeparator -->
<StaticResource x:Key="AppBarSeparatorBackground" ResourceKey="SemiColorBorder" />
<!-- CommandBar -->

View File

@@ -9,6 +9,8 @@
<StaticResource x:Key="AppBarToggleButtonCheckedForeground" ResourceKey="SemiColorHighlightText" />
<StaticResource x:Key="AppBarToggleButtonCheckedBackground" ResourceKey="SemiColorHighlight" />
<StaticResource x:Key="AppBarToggleButtonCheckedPointeroverBackground" ResourceKey="SemiColorButtonText" />
<StaticResource x:Key="AppBarToggleButtonCheckedPressedBackground" ResourceKey="SemiColorButtonFace" />
<StaticResource x:Key="AppBarToggleButtonCheckedDisabledForeground" ResourceKey="SemiColorGrayText" />
<!-- AppBarSeparator -->
<StaticResource x:Key="AppBarSeparatorBackground" ResourceKey="SemiColorWindowText" />
<!-- CommandBar -->

View File

@@ -9,6 +9,8 @@
<StaticResource x:Key="AppBarToggleButtonCheckedForeground" ResourceKey="SemiColorPrimary" />
<StaticResource x:Key="AppBarToggleButtonCheckedBackground" ResourceKey="SemiColorPrimaryLight" />
<StaticResource x:Key="AppBarToggleButtonCheckedPointeroverBackground" ResourceKey="SemiColorPrimaryLightPointerover" />
<StaticResource x:Key="AppBarToggleButtonCheckedPressedBackground" ResourceKey="SemiColorPrimaryLightActive" />
<StaticResource x:Key="AppBarToggleButtonCheckedDisabledForeground" ResourceKey="SemiColorPrimaryDisabled" />
<!-- AppBarSeparator -->
<StaticResource x:Key="AppBarSeparatorBackground" ResourceKey="SemiColorBorder" />
<!-- CommandBar -->