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

View File

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

View File

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

View File

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

View File

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