Browse Source

Rename AppBar controls (#21041)

* Renamed AppBar buttons and separator

* CommandBarSeparator inherit from Separator

* Added suppressions
pull/20292/merge
Javier Suárez 2 months ago
committed by GitHub
parent
commit
94c809f84e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 36
      api/Avalonia.nupkg.xml
  2. 24
      samples/ControlCatalog/Pages/CommandBar/CommandBarCustomizationPage.xaml
  3. 12
      samples/ControlCatalog/Pages/CommandBar/CommandBarDynamicOverflowPage.xaml
  4. 10
      samples/ControlCatalog/Pages/CommandBar/CommandBarEventsPage.xaml
  5. 18
      samples/ControlCatalog/Pages/CommandBar/CommandBarEventsPage.xaml.cs
  6. 56
      samples/ControlCatalog/Pages/CommandBar/CommandBarFirstLookPage.xaml
  7. 4
      samples/ControlCatalog/Pages/CommandBar/CommandBarFirstLookPage.xaml.cs
  8. 24
      samples/ControlCatalog/Pages/CommandBar/CommandBarLabelPositionPage.xaml
  9. 10
      samples/ControlCatalog/Pages/CommandBar/CommandBarOverflowPage.xaml
  10. 4
      samples/ControlCatalog/Pages/CommandBar/CommandBarOverflowPage.xaml.cs
  11. 28
      samples/ControlCatalog/Pages/CommandBar/CommandBarTogglePage.xaml
  12. 2
      samples/ControlCatalog/Pages/CommandBarPage.xaml.cs
  13. 20
      samples/ControlCatalog/Pages/ContentPage/ContentPageCommandBarPage.xaml.cs
  14. 16
      samples/ControlCatalog/Pages/NavigationPage/NavigationPageToolbarPage.xaml.cs
  15. 12
      src/Avalonia.Controls/CommandBar/CommandBar.cs
  16. 20
      src/Avalonia.Controls/CommandBar/CommandBarButton.cs
  17. 8
      src/Avalonia.Controls/CommandBar/CommandBarSeparator.cs
  18. 20
      src/Avalonia.Controls/CommandBar/CommandBarToggleButton.cs
  19. 38
      src/Avalonia.Themes.Fluent/Controls/CommandBar.xaml
  20. 4
      src/Avalonia.Themes.Fluent/Controls/NavigationPage.xaml
  21. 28
      src/Avalonia.Themes.Simple/Controls/CommandBar.xaml
  22. 182
      tests/Avalonia.Controls.UnitTests/CommandBarTests.cs
  23. 16
      tests/Avalonia.RenderTests/Controls/CommandBarTests.cs
  24. 8
      tests/Avalonia.RenderTests/Controls/ContentPageTests.cs

36
api/Avalonia.nupkg.xml

@ -5821,4 +5821,40 @@
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Controls.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Controls.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Avalonia.Controls.AppBarButton</Target>
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Controls.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Controls.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Avalonia.Controls.AppBarSeparator</Target>
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Controls.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Controls.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Avalonia.Controls.AppBarToggleButton</Target>
<Left>baseline/Avalonia/lib/net10.0/Avalonia.Controls.dll</Left>
<Right>current/Avalonia/lib/net10.0/Avalonia.Controls.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Avalonia.Controls.AppBarButton</Target>
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Controls.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Controls.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Avalonia.Controls.AppBarSeparator</Target>
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Controls.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Controls.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Avalonia.Controls.AppBarToggleButton</Target>
<Left>baseline/Avalonia/lib/net8.0/Avalonia.Controls.dll</Left>
<Right>current/Avalonia/lib/net8.0/Avalonia.Controls.dll</Right>
</Suppression>
</Suppressions>

24
samples/ControlCatalog/Pages/CommandBar/CommandBarCustomizationPage.xaml

@ -15,9 +15,9 @@
<TextBlock Text="Live Preview" FontWeight="SemiBold" FontSize="13" />
<CommandBar x:Name="LiveBar">
<CommandBar.PrimaryCommands>
<AppBarButton Label="New"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Save"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Share"><AppBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="New"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Save"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Share"><CommandBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
@ -74,7 +74,7 @@
<TextBlock Text="About" FontWeight="SemiBold" />
<TextBlock Text="CommandBar inherits from TemplatedControl, so Background, Foreground, BorderBrush, BorderThickness, and CornerRadius are available out of the box."
FontSize="12" Opacity="0.7" TextWrapping="Wrap" />
<TextBlock Text="Foreground is an inherited property: setting it on the CommandBar cascades to all PathIcons inside AppBarButton/AppBarToggleButton."
<TextBlock Text="Foreground is an inherited property: setting it on the CommandBar cascades to all PathIcons inside CommandBarButton/CommandBarToggleButton."
FontSize="12" Opacity="0.7" TextWrapping="Wrap" Margin="0,4,0,0" />
</StackPanel>
</ScrollViewer>
@ -89,20 +89,20 @@
<TextBlock Text="Default theme" FontSize="12" Opacity="0.7" />
<CommandBar OverflowButtonVisibility="Collapsed">
<AppBarButton Label="New"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Save"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="New"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Save"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar>
<TextBlock Text="Solid color" FontSize="12" Opacity="0.7" />
<CommandBar Background="#0078D4" Foreground="White" OverflowButtonVisibility="Collapsed">
<AppBarButton Label="New"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Save"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="New"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Save"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar>
<TextBlock Text="Dark" FontSize="12" Opacity="0.7" />
<CommandBar Background="#1C1C1E" Foreground="White" OverflowButtonVisibility="Collapsed">
<AppBarButton Label="New"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Save"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="New"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Save"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar>
<TextBlock Text="Pill shape (CornerRadius=20)" FontSize="12" Opacity="0.7" />
@ -111,8 +111,8 @@
BorderBrush="#CCCCCC"
BorderThickness="1"
OverflowButtonVisibility="Collapsed">
<AppBarButton Label="New"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Save"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="New"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Save"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar>
</StackPanel>
</ScrollViewer>

12
samples/ControlCatalog/Pages/CommandBar/CommandBarDynamicOverflowPage.xaml

@ -61,12 +61,12 @@
ClipToBounds="True">
<CommandBar x:Name="DemoBar" IsDynamicOverflowEnabled="True">
<CommandBar.PrimaryCommands>
<AppBarButton Label="New" DynamicOverflowOrder="0"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Save" DynamicOverflowOrder="0"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Share" DynamicOverflowOrder="1"><AppBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Bold" DynamicOverflowOrder="2"><AppBarButton.Icon><PathIcon Data="{StaticResource BoldIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Italic" DynamicOverflowOrder="2"><AppBarButton.Icon><PathIcon Data="{StaticResource ItalicIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Delete" DynamicOverflowOrder="3"><AppBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="New" DynamicOverflowOrder="0"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Save" DynamicOverflowOrder="0"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Share" DynamicOverflowOrder="1"><CommandBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Bold" DynamicOverflowOrder="2"><CommandBarButton.Icon><PathIcon Data="{StaticResource BoldIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Italic" DynamicOverflowOrder="2"><CommandBarButton.Icon><PathIcon Data="{StaticResource ItalicIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Delete" DynamicOverflowOrder="3"><CommandBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
</Border>

10
samples/ControlCatalog/Pages/CommandBar/CommandBarEventsPage.xaml

@ -64,13 +64,13 @@
<CommandBar x:Name="DemoBar"
OverflowButtonVisibility="Auto">
<CommandBar.PrimaryCommands>
<AppBarButton Label="New"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Save"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Share"><AppBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="New"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Save"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Share"><CommandBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar.PrimaryCommands>
<CommandBar.SecondaryCommands>
<AppBarButton Label="Export"><AppBarButton.Icon><PathIcon Data="{StaticResource ExportIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Delete"><AppBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="Export"><CommandBarButton.Icon><PathIcon Data="{StaticResource ExportIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Delete"><CommandBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar.SecondaryCommands>
</CommandBar>

18
samples/ControlCatalog/Pages/CommandBar/CommandBarEventsPage.xaml.cs

@ -141,13 +141,13 @@ namespace ControlCatalog.Pages
private void OnCommandItemClick(object? sender, RoutedEventArgs e)
{
if (sender is AppBarButton button)
if (sender is CommandBarButton button)
AppendLog($"Click, {button.Label}, {DescribePlacement(button)}");
}
private AppBarButton CreateButton(string label)
private CommandBarButton CreateButton(string label)
{
var button = new AppBarButton
var button = new CommandBarButton
{
Label = label,
Icon = new PathIcon
@ -170,14 +170,14 @@ namespace ControlCatalog.Pages
{
foreach (var item in items)
{
if (item is AppBarButton button)
if (item is CommandBarButton button)
button.Click -= OnCommandItemClick;
}
}
private void AttachItemHandler(ICommandBarElement item)
{
if (item is not AppBarButton button)
if (item is not CommandBarButton button)
return;
button.Click -= OnCommandItemClick;
@ -191,10 +191,10 @@ namespace ControlCatalog.Pages
return;
var item = items[^1];
var label = item is AppBarButton button ? button.Label ?? "(unnamed)" : item.GetType().Name;
var label = item is CommandBarButton button ? button.Label ?? "(unnamed)" : item.GetType().Name;
if (item is AppBarButton appBarButton)
appBarButton.Click -= OnCommandItemClick;
if (item is CommandBarButton commandBarButton)
commandBarButton.Click -= OnCommandItemClick;
items.RemoveAt(items.Count - 1);
@ -202,7 +202,7 @@ namespace ControlCatalog.Pages
RefreshState();
}
private static string DescribePlacement(AppBarButton button)
private static string DescribePlacement(CommandBarButton button)
{
return button.IsInOverflow ? "overflow" : "primary";
}

56
samples/ControlCatalog/Pages/CommandBar/CommandBarFirstLookPage.xaml

@ -36,7 +36,7 @@
<Separator />
<TextBlock Text="Separators" FontWeight="SemiBold" />
<TextBlock Text="AppBarSeparator creates visual dividers between command groups."
<TextBlock Text="CommandBarSeparator creates visual dividers between command groups."
FontSize="12" Opacity="0.7" TextWrapping="Wrap" />
</StackPanel>
</ScrollViewer>
@ -52,35 +52,35 @@
<TextBlock Text="Document Editor" VerticalAlignment="Center" Margin="8,0" />
</CommandBar.Content>
<CommandBar.PrimaryCommands>
<AppBarButton Label="New" Click="OnButtonClick">
<AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon>
</AppBarButton>
<AppBarButton Label="Save" Click="OnButtonClick">
<AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon>
</AppBarButton>
<AppBarSeparator />
<AppBarToggleButton Label="Bold" IsCheckedChanged="OnToggleChanged">
<AppBarToggleButton.Icon><PathIcon Data="{StaticResource BoldIcon}" /></AppBarToggleButton.Icon>
</AppBarToggleButton>
<AppBarToggleButton Label="Italic" IsCheckedChanged="OnToggleChanged">
<AppBarToggleButton.Icon><PathIcon Data="{StaticResource ItalicIcon}" /></AppBarToggleButton.Icon>
</AppBarToggleButton>
<AppBarSeparator />
<AppBarButton Label="Share" Click="OnButtonClick">
<AppBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></AppBarButton.Icon>
</AppBarButton>
<CommandBarButton Label="New" Click="OnButtonClick">
<CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon>
</CommandBarButton>
<CommandBarButton Label="Save" Click="OnButtonClick">
<CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon>
</CommandBarButton>
<CommandBarSeparator />
<CommandBarToggleButton Label="Bold" IsCheckedChanged="OnToggleChanged">
<CommandBarToggleButton.Icon><PathIcon Data="{StaticResource BoldIcon}" /></CommandBarToggleButton.Icon>
</CommandBarToggleButton>
<CommandBarToggleButton Label="Italic" IsCheckedChanged="OnToggleChanged">
<CommandBarToggleButton.Icon><PathIcon Data="{StaticResource ItalicIcon}" /></CommandBarToggleButton.Icon>
</CommandBarToggleButton>
<CommandBarSeparator />
<CommandBarButton Label="Share" Click="OnButtonClick">
<CommandBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></CommandBarButton.Icon>
</CommandBarButton>
</CommandBar.PrimaryCommands>
<CommandBar.SecondaryCommands>
<AppBarButton Label="Export" Click="OnButtonClick">
<AppBarButton.Icon><PathIcon Data="{StaticResource ExportIcon}" /></AppBarButton.Icon>
</AppBarButton>
<AppBarButton Label="Print" Click="OnButtonClick">
<AppBarButton.Icon><PathIcon Data="{StaticResource PrintIcon}" /></AppBarButton.Icon>
</AppBarButton>
<AppBarSeparator />
<AppBarButton Label="Delete" Click="OnButtonClick">
<AppBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></AppBarButton.Icon>
</AppBarButton>
<CommandBarButton Label="Export" Click="OnButtonClick">
<CommandBarButton.Icon><PathIcon Data="{StaticResource ExportIcon}" /></CommandBarButton.Icon>
</CommandBarButton>
<CommandBarButton Label="Print" Click="OnButtonClick">
<CommandBarButton.Icon><PathIcon Data="{StaticResource PrintIcon}" /></CommandBarButton.Icon>
</CommandBarButton>
<CommandBarSeparator />
<CommandBarButton Label="Delete" Click="OnButtonClick">
<CommandBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></CommandBarButton.Icon>
</CommandBarButton>
</CommandBar.SecondaryCommands>
</CommandBar>

4
samples/ControlCatalog/Pages/CommandBar/CommandBarFirstLookPage.xaml.cs

@ -12,13 +12,13 @@ namespace ControlCatalog.Pages
private void OnButtonClick(object? sender, RoutedEventArgs e)
{
if (sender is AppBarButton btn)
if (sender is CommandBarButton btn)
StatusText.Text = $"{btn.Label} clicked";
}
private void OnToggleChanged(object? sender, RoutedEventArgs e)
{
if (sender is AppBarToggleButton btn)
if (sender is CommandBarToggleButton btn)
StatusText.Text = btn.IsChecked == true
? $"{btn.Label} enabled"
: $"{btn.Label} disabled";

24
samples/ControlCatalog/Pages/CommandBar/CommandBarLabelPositionPage.xaml

@ -15,10 +15,10 @@
<TextBlock Text="Bottom (default)" FontWeight="SemiBold" />
<TextBlock Text="Label appears below the icon." FontSize="12" Opacity="0.7" />
<CommandBar DefaultLabelPosition="Bottom" OverflowButtonVisibility="Collapsed">
<AppBarButton Label="New"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Save"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Share"><AppBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Delete"><AppBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="New"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Save"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Share"><CommandBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Delete"><CommandBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar>
<Separator />
@ -26,10 +26,10 @@
<TextBlock Text="Right" FontWeight="SemiBold" />
<TextBlock Text="Label appears to the right of the icon." FontSize="12" Opacity="0.7" />
<CommandBar DefaultLabelPosition="Right" OverflowButtonVisibility="Collapsed">
<AppBarButton Label="New"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Save"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Share"><AppBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Delete"><AppBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="New"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Save"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Share"><CommandBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Delete"><CommandBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar>
<Separator />
@ -37,10 +37,10 @@
<TextBlock Text="Collapsed (icon only)" FontWeight="SemiBold" />
<TextBlock Text="No label shown. Use ToolTip.Tip to preserve accessibility." FontSize="12" Opacity="0.7" />
<CommandBar DefaultLabelPosition="Collapsed" OverflowButtonVisibility="Collapsed">
<AppBarButton ToolTip.Tip="New"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton ToolTip.Tip="Save"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton ToolTip.Tip="Share"><AppBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton ToolTip.Tip="Delete"><AppBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton ToolTip.Tip="New"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton ToolTip.Tip="Save"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton ToolTip.Tip="Share"><CommandBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton ToolTip.Tip="Delete"><CommandBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar>
</StackPanel>
</ScrollViewer>

10
samples/ControlCatalog/Pages/CommandBar/CommandBarOverflowPage.xaml

@ -59,13 +59,13 @@
<CommandBar x:Name="DemoBar" IsDynamicOverflowEnabled="True">
<CommandBar.PrimaryCommands>
<AppBarButton Label="New"><AppBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Save"><AppBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Share"><AppBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="New"><CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Save"><CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Share"><CommandBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar.PrimaryCommands>
<CommandBar.SecondaryCommands>
<AppBarButton Label="Export"><AppBarButton.Icon><PathIcon Data="{StaticResource ExportIcon}" /></AppBarButton.Icon></AppBarButton>
<AppBarButton Label="Delete"><AppBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></AppBarButton.Icon></AppBarButton>
<CommandBarButton Label="Export"><CommandBarButton.Icon><PathIcon Data="{StaticResource ExportIcon}" /></CommandBarButton.Icon></CommandBarButton>
<CommandBarButton Label="Delete"><CommandBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></CommandBarButton.Icon></CommandBarButton>
</CommandBar.SecondaryCommands>
</CommandBar>
</StackPanel>

4
samples/ControlCatalog/Pages/CommandBar/CommandBarOverflowPage.xaml.cs

@ -42,13 +42,13 @@ namespace ControlCatalog.Pages
private void OnAddPrimary(object? sender, RoutedEventArgs e)
{
_primaryCount++;
DemoBar.PrimaryCommands.Add(new AppBarButton { Label = $"Cmd {_primaryCount}" });
DemoBar.PrimaryCommands.Add(new CommandBarButton { Label = $"Cmd {_primaryCount}" });
}
private void OnAddSecondary(object? sender, RoutedEventArgs e)
{
_secondaryCount++;
DemoBar.SecondaryCommands.Add(new AppBarButton { Label = $"Sec {_secondaryCount}" });
DemoBar.SecondaryCommands.Add(new CommandBarButton { Label = $"Sec {_secondaryCount}" });
}
}
}

28
samples/ControlCatalog/Pages/CommandBar/CommandBarTogglePage.xaml

@ -28,7 +28,7 @@
<Separator />
<TextBlock Text="About" FontWeight="SemiBold" />
<TextBlock Text="AppBarToggleButton maintains checked/unchecked state. When checked, it shows a highlight background. Bind IsChecked to a boolean property."
<TextBlock Text="CommandBarToggleButton maintains checked/unchecked state. When checked, it shows a highlight background. Bind IsChecked to a boolean property."
FontSize="12" Opacity="0.7" TextWrapping="Wrap" />
</StackPanel>
</ScrollViewer>
@ -37,25 +37,25 @@
<ScrollViewer>
<StackPanel Spacing="12" Margin="12,12,12,0">
<TextBlock Classes="h2">AppBarToggleButton supports on/off states for formatting and feature toggles.</TextBlock>
<TextBlock Classes="h2">CommandBarToggleButton supports on/off states for formatting and feature toggles.</TextBlock>
<TextBlock Text="Text Formatting" FontWeight="SemiBold" />
<CommandBar x:Name="FormatBar" OverflowButtonVisibility="Collapsed">
<AppBarToggleButton x:Name="BoldToggle"
<CommandBarToggleButton x:Name="BoldToggle"
Label="Bold"
IsCheckedChanged="OnFormatChanged">
<AppBarToggleButton.Icon><PathIcon Data="{StaticResource BoldIcon}" /></AppBarToggleButton.Icon>
</AppBarToggleButton>
<AppBarToggleButton x:Name="ItalicToggle"
<CommandBarToggleButton.Icon><PathIcon Data="{StaticResource BoldIcon}" /></CommandBarToggleButton.Icon>
</CommandBarToggleButton>
<CommandBarToggleButton x:Name="ItalicToggle"
Label="Italic"
IsCheckedChanged="OnFormatChanged">
<AppBarToggleButton.Icon><PathIcon Data="{StaticResource ItalicIcon}" /></AppBarToggleButton.Icon>
</AppBarToggleButton>
<AppBarToggleButton x:Name="UnderlineToggle"
<CommandBarToggleButton.Icon><PathIcon Data="{StaticResource ItalicIcon}" /></CommandBarToggleButton.Icon>
</CommandBarToggleButton>
<CommandBarToggleButton x:Name="UnderlineToggle"
Label="Underline"
IsCheckedChanged="OnFormatChanged">
<AppBarToggleButton.Icon><PathIcon Data="{StaticResource UnderlineIcon}" /></AppBarToggleButton.Icon>
</AppBarToggleButton>
<CommandBarToggleButton.Icon><PathIcon Data="{StaticResource UnderlineIcon}" /></CommandBarToggleButton.Icon>
</CommandBarToggleButton>
</CommandBar>
<TextBlock x:Name="FormatStatus"
@ -67,9 +67,9 @@
<TextBlock Text="Favorite" FontWeight="SemiBold" />
<CommandBar OverflowButtonVisibility="Collapsed">
<AppBarToggleButton Label="Favorite">
<AppBarToggleButton.Icon><PathIcon Data="{StaticResource FavoriteIcon}" /></AppBarToggleButton.Icon>
</AppBarToggleButton>
<CommandBarToggleButton Label="Favorite">
<CommandBarToggleButton.Icon><PathIcon Data="{StaticResource FavoriteIcon}" /></CommandBarToggleButton.Icon>
</CommandBarToggleButton>
</CommandBar>
</StackPanel>
</ScrollViewer>

2
samples/ControlCatalog/Pages/CommandBarPage.xaml.cs

@ -13,7 +13,7 @@ namespace ControlCatalog.Pages
{
// Overview
("Overview", "First Look", "A CommandBar with primary commands, secondary overflow menu, and custom content area.", () => new CommandBarFirstLookPage()),
("Overview", "Toggle Buttons", "AppBarToggleButton for stateful actions like Bold, Italic, and Favorite.", () => new CommandBarTogglePage()),
("Overview", "Toggle Buttons", "CommandBarToggleButton for stateful actions like Bold, Italic, and Favorite.", () => new CommandBarTogglePage()),
// Appearance
("Appearance", "Label Positions", "Configure label position: Bottom (default), Right, or Collapsed (icon only).", () => new CommandBarLabelPositionPage()),

20
samples/ControlCatalog/Pages/ContentPage/ContentPageCommandBarPage.xaml.cs

@ -78,7 +78,7 @@ namespace ControlCatalog.Pages
private void OnAddPrimary(object? sender, RoutedEventArgs e)
{
_itemCounter++;
var btn = new AppBarButton { Label = $"Action {_itemCounter}" };
var btn = new CommandBarButton { Label = $"Action {_itemCounter}" };
if (UseIconCheck.IsChecked == true)
{
var preset = IconPresets[(_itemCounter - 1) % IconPresets.Length];
@ -93,13 +93,13 @@ namespace ControlCatalog.Pages
private void OnAddSecondary(object? sender, RoutedEventArgs e)
{
_itemCounter++;
_secondaryItems.Add(new AppBarButton { Label = $"Item {_itemCounter}" });
_secondaryItems.Add(new CommandBarButton { Label = $"Item {_itemCounter}" });
RebuildCommandBar();
}
private void OnAddSeparator(object? sender, RoutedEventArgs e)
{
_primaryItems.Add(new AppBarSeparator());
_primaryItems.Add(new CommandBarSeparator());
RebuildCommandBar();
}
@ -177,26 +177,26 @@ namespace ControlCatalog.Pages
foreach (var item in _primaryItems)
{
if (item is AppBarButton btn)
if (item is CommandBarButton btn)
{
PathIcon? icon = null;
if (btn.Icon is PathIcon src)
icon = new PathIcon { Data = src.Data };
commandBar.PrimaryCommands.Add(new AppBarButton
commandBar.PrimaryCommands.Add(new CommandBarButton
{
Label = btn.Label,
Icon = icon,
IsCompact = btn.IsCompact,
});
}
else if (item is AppBarSeparator)
commandBar.PrimaryCommands.Add(new AppBarSeparator());
else if (item is CommandBarSeparator)
commandBar.PrimaryCommands.Add(new CommandBarSeparator());
}
foreach (var item in _secondaryItems)
{
if (item is AppBarButton btn)
commandBar.SecondaryCommands.Add(new AppBarButton { Label = btn.Label });
if (item is CommandBarButton btn)
commandBar.SecondaryCommands.Add(new CommandBarButton { Label = btn.Label });
}
if (_position == "Top")
@ -204,7 +204,7 @@ namespace ControlCatalog.Pages
else
NavigationPage.SetBottomCommandBar(activePage, commandBar);
var primaryCount = _primaryItems.Count(i => i is AppBarButton);
var primaryCount = _primaryItems.Count(i => i is CommandBarButton);
var secondaryCount = _secondaryItems.Count;
StatusText.Text = $"{primaryCount} primary, {secondaryCount} secondary ({_position})";
}

16
samples/ControlCatalog/Pages/NavigationPage/NavigationPageToolbarPage.xaml.cs

@ -49,7 +49,7 @@ namespace ControlCatalog.Pages
private void OnAddPrimary(object? sender, RoutedEventArgs e)
{
_itemCount++;
_rootCommandBar.PrimaryCommands.Add(new AppBarButton
_rootCommandBar.PrimaryCommands.Add(new CommandBarButton
{
Label = $"Item {_itemCount}",
Icon = new PathIcon { Data = (Geometry)this.FindResource("AddIcon")! }
@ -60,7 +60,7 @@ namespace ControlCatalog.Pages
private void OnAddSecondary(object? sender, RoutedEventArgs e)
{
_itemCount++;
_rootCommandBar.SecondaryCommands.Add(new AppBarButton
_rootCommandBar.SecondaryCommands.Add(new CommandBarButton
{
Label = $"Secondary {_itemCount}"
});
@ -69,13 +69,13 @@ namespace ControlCatalog.Pages
private void OnAddPrimarySeparator(object? sender, RoutedEventArgs e)
{
_rootCommandBar.PrimaryCommands.Add(new AppBarSeparator());
_rootCommandBar.PrimaryCommands.Add(new CommandBarSeparator());
UpdateStatus();
}
private void OnAddSecondarySeparator(object? sender, RoutedEventArgs e)
{
_rootCommandBar.SecondaryCommands.Add(new AppBarSeparator());
_rootCommandBar.SecondaryCommands.Add(new CommandBarSeparator());
UpdateStatus();
}
@ -125,13 +125,13 @@ namespace ControlCatalog.Pages
{
PrimaryCommands =
{
new AppBarButton { Label = "Search", Icon = new PathIcon { Data = (Geometry)this.FindResource("SearchIcon")! } },
new AppBarButton { Label = "Share", Icon = new PathIcon { Data = (Geometry)this.FindResource("ShareIcon")! } },
new AppBarButton { Label = "Edit", Icon = new PathIcon { Data = (Geometry)this.FindResource("EditIcon")! } },
new CommandBarButton { Label = "Search", Icon = new PathIcon { Data = (Geometry)this.FindResource("SearchIcon")! } },
new CommandBarButton { Label = "Share", Icon = new PathIcon { Data = (Geometry)this.FindResource("ShareIcon")! } },
new CommandBarButton { Label = "Edit", Icon = new PathIcon { Data = (Geometry)this.FindResource("EditIcon")! } },
},
SecondaryCommands =
{
new AppBarButton { Label = "Delete", Icon = new PathIcon { Data = (Geometry)this.FindResource("DeleteIcon")! } }
new CommandBarButton { Label = "Delete", Icon = new PathIcon { Data = (Geometry)this.FindResource("DeleteIcon")! } }
}
};
}

12
src/Avalonia.Controls/CommandBar/CommandBar.cs

@ -516,7 +516,7 @@ namespace Avalonia.Controls
int primaryNonSepCount = 0;
foreach (var item in PrimaryCommands)
if (item is not AppBarSeparator)
if (item is not CommandBarSeparator)
primaryNonSepCount++;
const double overflowButtonWidth = 48;
@ -554,7 +554,7 @@ namespace Avalonia.Controls
for (var i = 0; i < prioritized.Count; i++)
{
var idx = prioritized[i].Index;
if (PrimaryCommands[idx] is AppBarSeparator)
if (PrimaryCommands[idx] is CommandBarSeparator)
visibleIndices.Add(idx);
else if (nonSeparatorCount < maxItems)
{
@ -596,8 +596,8 @@ namespace Avalonia.Controls
private static int GetDynamicOverflowOrder(ICommandBarElement element) => element switch
{
AppBarButton b => b.DynamicOverflowOrder,
AppBarToggleButton t => t.DynamicOverflowOrder,
CommandBarButton b => b.DynamicOverflowOrder,
CommandBarToggleButton t => t.DynamicOverflowOrder,
_ => 0
};
@ -615,9 +615,9 @@ namespace Avalonia.Controls
{
element.IsCompact = DefaultLabelPosition == CommandBarDefaultLabelPosition.Collapsed;
if (element is AppBarButton abb)
if (element is CommandBarButton abb)
abb.LabelPosition = DefaultLabelPosition;
else if (element is AppBarToggleButton atb)
else if (element is CommandBarToggleButton atb)
atb.LabelPosition = DefaultLabelPosition;
}

20
src/Avalonia.Controls/CommandBar/AppBarButton.cs → src/Avalonia.Controls/CommandBar/CommandBarButton.cs

@ -3,49 +3,49 @@ namespace Avalonia.Controls
/// <summary>
/// A button for use in a <see cref="CommandBar"/>.
/// </summary>
public class AppBarButton : Button, ICommandBarElement
public class CommandBarButton : Button, ICommandBarElement
{
static AppBarButton()
static CommandBarButton()
{
ForegroundProperty.Changed.AddClassHandler<AppBarButton>((x, _) => x.UpdateIconForeground());
IconProperty.Changed.AddClassHandler<AppBarButton>((x, _) => x.UpdateIconForeground());
ForegroundProperty.Changed.AddClassHandler<CommandBarButton>((x, _) => x.UpdateIconForeground());
IconProperty.Changed.AddClassHandler<CommandBarButton>((x, _) => x.UpdateIconForeground());
}
/// <summary>
/// Defines the <see cref="Label"/> property.
/// </summary>
public static readonly StyledProperty<string?> LabelProperty =
AvaloniaProperty.Register<AppBarButton, string?>(nameof(Label));
AvaloniaProperty.Register<CommandBarButton, string?>(nameof(Label));
/// <summary>
/// Defines the <see cref="Icon"/> property.
/// </summary>
public static readonly StyledProperty<object?> IconProperty =
AvaloniaProperty.Register<AppBarButton, object?>(nameof(Icon));
AvaloniaProperty.Register<CommandBarButton, object?>(nameof(Icon));
/// <summary>
/// Defines the <see cref="IsCompact"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsCompactProperty =
AvaloniaProperty.Register<AppBarButton, bool>(nameof(IsCompact));
AvaloniaProperty.Register<CommandBarButton, bool>(nameof(IsCompact));
/// <summary>
/// Defines the <see cref="DynamicOverflowOrder"/> property.
/// </summary>
public static readonly StyledProperty<int> DynamicOverflowOrderProperty =
AvaloniaProperty.Register<AppBarButton, int>(nameof(DynamicOverflowOrder));
AvaloniaProperty.Register<CommandBarButton, int>(nameof(DynamicOverflowOrder));
/// <summary>
/// Defines the <see cref="LabelPosition"/> property.
/// </summary>
public static readonly StyledProperty<CommandBarDefaultLabelPosition> LabelPositionProperty =
AvaloniaProperty.Register<AppBarButton, CommandBarDefaultLabelPosition>(nameof(LabelPosition), CommandBarDefaultLabelPosition.Bottom);
AvaloniaProperty.Register<CommandBarButton, CommandBarDefaultLabelPosition>(nameof(LabelPosition), CommandBarDefaultLabelPosition.Bottom);
/// <summary>
/// Defines the <see cref="IsInOverflow"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsInOverflowProperty =
AvaloniaProperty.Register<AppBarButton, bool>(nameof(IsInOverflow));
AvaloniaProperty.Register<CommandBarButton, bool>(nameof(IsInOverflow));
/// <summary>
/// Gets or sets the text label for the button.

8
src/Avalonia.Controls/CommandBar/AppBarSeparator.cs → src/Avalonia.Controls/CommandBar/CommandBarSeparator.cs

@ -1,23 +1,21 @@
using Avalonia.Controls.Primitives;
namespace Avalonia.Controls
{
/// <summary>
/// A visual separator for use in a <see cref="CommandBar"/>.
/// </summary>
public class AppBarSeparator : TemplatedControl, ICommandBarElement
public class CommandBarSeparator : Separator, ICommandBarElement
{
/// <summary>
/// Defines the <see cref="IsCompact"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsCompactProperty =
AvaloniaProperty.Register<AppBarSeparator, bool>(nameof(IsCompact));
AvaloniaProperty.Register<CommandBarSeparator, bool>(nameof(IsCompact));
/// <summary>
/// Defines the <see cref="IsInOverflow"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsInOverflowProperty =
AvaloniaProperty.Register<AppBarSeparator, bool>(nameof(IsInOverflow));
AvaloniaProperty.Register<CommandBarSeparator, bool>(nameof(IsInOverflow));
/// <summary>
/// Gets or sets whether the separator is in compact mode.

20
src/Avalonia.Controls/CommandBar/AppBarToggleButton.cs → src/Avalonia.Controls/CommandBar/CommandBarToggleButton.cs

@ -5,49 +5,49 @@ namespace Avalonia.Controls
/// <summary>
/// A toggle button for use in a <see cref="CommandBar"/>.
/// </summary>
public class AppBarToggleButton : ToggleButton, ICommandBarElement
public class CommandBarToggleButton : ToggleButton, ICommandBarElement
{
static AppBarToggleButton()
static CommandBarToggleButton()
{
ForegroundProperty.Changed.AddClassHandler<AppBarToggleButton>((x, _) => x.UpdateIconForeground());
IconProperty.Changed.AddClassHandler<AppBarToggleButton>((x, _) => x.UpdateIconForeground());
ForegroundProperty.Changed.AddClassHandler<CommandBarToggleButton>((x, _) => x.UpdateIconForeground());
IconProperty.Changed.AddClassHandler<CommandBarToggleButton>((x, _) => x.UpdateIconForeground());
}
/// <summary>
/// Defines the <see cref="Label"/> property.
/// </summary>
public static readonly StyledProperty<string?> LabelProperty =
AvaloniaProperty.Register<AppBarToggleButton, string?>(nameof(Label));
AvaloniaProperty.Register<CommandBarToggleButton, string?>(nameof(Label));
/// <summary>
/// Defines the <see cref="Icon"/> property.
/// </summary>
public static readonly StyledProperty<object?> IconProperty =
AvaloniaProperty.Register<AppBarToggleButton, object?>(nameof(Icon));
AvaloniaProperty.Register<CommandBarToggleButton, object?>(nameof(Icon));
/// <summary>
/// Defines the <see cref="IsCompact"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsCompactProperty =
AvaloniaProperty.Register<AppBarToggleButton, bool>(nameof(IsCompact));
AvaloniaProperty.Register<CommandBarToggleButton, bool>(nameof(IsCompact));
/// <summary>
/// Defines the <see cref="DynamicOverflowOrder"/> property.
/// </summary>
public static readonly StyledProperty<int> DynamicOverflowOrderProperty =
AvaloniaProperty.Register<AppBarToggleButton, int>(nameof(DynamicOverflowOrder));
AvaloniaProperty.Register<CommandBarToggleButton, int>(nameof(DynamicOverflowOrder));
/// <summary>
/// Defines the <see cref="LabelPosition"/> property.
/// </summary>
public static readonly StyledProperty<CommandBarDefaultLabelPosition> LabelPositionProperty =
AvaloniaProperty.Register<AppBarToggleButton, CommandBarDefaultLabelPosition>(nameof(LabelPosition), CommandBarDefaultLabelPosition.Bottom);
AvaloniaProperty.Register<CommandBarToggleButton, CommandBarDefaultLabelPosition>(nameof(LabelPosition), CommandBarDefaultLabelPosition.Bottom);
/// <summary>
/// Defines the <see cref="IsInOverflow"/> property.
/// </summary>
public static readonly StyledProperty<bool> IsInOverflowProperty =
AvaloniaProperty.Register<AppBarToggleButton, bool>(nameof(IsInOverflow));
AvaloniaProperty.Register<CommandBarToggleButton, bool>(nameof(IsInOverflow));
/// <summary>
/// Gets or sets the text label for the button.

38
src/Avalonia.Themes.Fluent/Controls/CommandBar.xaml

@ -5,29 +5,29 @@
<Border Padding="20" Width="600">
<StackPanel Spacing="12">
<CommandBar>
<AppBarButton Label="New">
<AppBarButton.Icon>
<CommandBarButton Label="New">
<CommandBarButton.Icon>
<PathIcon Data="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton Label="Save">
<AppBarButton.Icon>
</CommandBarButton.Icon>
</CommandBarButton>
<CommandBarButton Label="Save">
<CommandBarButton.Icon>
<PathIcon Data="M15,9H5V5H15M12,19A3,3 0 0,1 9,16A3,3 0 0,1 12,13A3,3 0 0,1 15,16A3,3 0 0,1 12,19M17,3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V7L17,3Z" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarSeparator />
<AppBarToggleButton Label="Bold">
<AppBarToggleButton.Icon>
</CommandBarButton.Icon>
</CommandBarButton>
<CommandBarSeparator />
<CommandBarToggleButton Label="Bold">
<CommandBarToggleButton.Icon>
<PathIcon Data="M15.6,10.79C17.04,10.07 18,8.64 18,7C18,4.79 16.21,3 14,3H7V21H14.73C16.78,21 18.5,19.37 18.5,17.32C18.5,15.82 17.72,14.53 16.5,13.77C16.2,13.59 15.9,13.44 15.6,13.32V10.79M10,6.5H13C13.83,6.5 14.5,7.17 14.5,8C14.5,8.83 13.83,9.5 13,9.5H10V6.5M13.5,17.5H10V14H13.5C14.33,14 15,14.67 15,15.5C15,16.33 14.33,17.5 13.5,17.5Z" />
</AppBarToggleButton.Icon>
</AppBarToggleButton>
</CommandBarToggleButton.Icon>
</CommandBarToggleButton>
</CommandBar>
</StackPanel>
</Border>
</Design.PreviewWith>
<!-- AppBarButton ControlTheme -->
<ControlTheme x:Key="{x:Type AppBarButton}" TargetType="AppBarButton">
<!-- CommandBarButton ControlTheme -->
<ControlTheme x:Key="{x:Type CommandBarButton}" TargetType="CommandBarButton">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
@ -108,8 +108,8 @@
</Style>
</ControlTheme>
<!-- AppBarToggleButton ControlTheme -->
<ControlTheme x:Key="{x:Type AppBarToggleButton}" TargetType="AppBarToggleButton">
<!-- CommandBarToggleButton ControlTheme -->
<ControlTheme x:Key="{x:Type CommandBarToggleButton}" TargetType="CommandBarToggleButton">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
@ -195,8 +195,8 @@
</Style>
</ControlTheme>
<!-- AppBarSeparator ControlTheme -->
<ControlTheme x:Key="{x:Type AppBarSeparator}" TargetType="AppBarSeparator">
<!-- CommandBarSeparator ControlTheme -->
<ControlTheme x:Key="{x:Type CommandBarSeparator}" TargetType="CommandBarSeparator">
<Setter Property="Width" Value="1" />
<Setter Property="MinHeight" Value="24" />
<Setter Property="Margin" Value="8,4" />

4
src/Avalonia.Themes.Fluent/Controls/NavigationPage.xaml

@ -159,11 +159,11 @@
<Setter Property="Padding" Value="0" />
<Setter Property="VerticalAlignment" Value="Stretch" />
</Style>
<Style Selector="AppBarButton">
<Style Selector="CommandBarButton">
<Setter Property="MinHeight" Value="0" />
<Setter Property="Padding" Value="8,0" />
</Style>
<Style Selector="AppBarToggleButton">
<Style Selector="CommandBarToggleButton">
<Setter Property="MinHeight" Value="0" />
<Setter Property="Padding" Value="8,0" />
</Style>

28
src/Avalonia.Themes.Simple/Controls/CommandBar.xaml

@ -5,23 +5,23 @@
<Border Padding="20" Width="500">
<StackPanel Spacing="8">
<CommandBar>
<AppBarButton Label="New">
<AppBarButton.Icon>
<CommandBarButton Label="New">
<CommandBarButton.Icon>
<PathIcon Data="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z" />
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton Label="Save">
<AppBarButton.Icon>
</CommandBarButton.Icon>
</CommandBarButton>
<CommandBarButton Label="Save">
<CommandBarButton.Icon>
<PathIcon Data="M15,9H5V5H15M12,19A3,3 0 0,1 9,16A3,3 0 0,1 12,13A3,3 0 0,1 15,16A3,3 0 0,1 12,19M17,3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V7L17,3Z" />
</AppBarButton.Icon>
</AppBarButton>
</CommandBarButton.Icon>
</CommandBarButton>
</CommandBar>
</StackPanel>
</Border>
</Design.PreviewWith>
<!-- AppBarButton ControlTheme -->
<ControlTheme x:Key="{x:Type AppBarButton}" TargetType="AppBarButton">
<!-- CommandBarButton ControlTheme -->
<ControlTheme x:Key="{x:Type CommandBarButton}" TargetType="CommandBarButton">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
@ -102,8 +102,8 @@
</Style>
</ControlTheme>
<!-- AppBarToggleButton ControlTheme -->
<ControlTheme x:Key="{x:Type AppBarToggleButton}" TargetType="AppBarToggleButton">
<!-- CommandBarToggleButton ControlTheme -->
<ControlTheme x:Key="{x:Type CommandBarToggleButton}" TargetType="CommandBarToggleButton">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
@ -190,8 +190,8 @@
</Style>
</ControlTheme>
<!-- AppBarSeparator ControlTheme -->
<ControlTheme x:Key="{x:Type AppBarSeparator}" TargetType="AppBarSeparator">
<!-- CommandBarSeparator ControlTheme -->
<ControlTheme x:Key="{x:Type CommandBarSeparator}" TargetType="CommandBarSeparator">
<Setter Property="Width" Value="1" />
<Setter Property="MinHeight" Value="24" />
<Setter Property="Margin" Value="8,4" />

182
tests/Avalonia.Controls.UnitTests/CommandBarTests.cs

@ -6,27 +6,27 @@ using Xunit;
namespace Avalonia.Controls.UnitTests;
public class AppBarButtonTests : ScopedTestBase
public class CommandBarButtonTests : ScopedTestBase
{
[Fact]
public void Label_DefaultIsNull()
=> Assert.Null(new AppBarButton().Label);
=> Assert.Null(new CommandBarButton().Label);
[Fact]
public void Label_RoundTrip()
{
var btn = new AppBarButton { Label = "Save" };
var btn = new CommandBarButton { Label = "Save" };
Assert.Equal("Save", btn.Label);
}
[Fact]
public void Icon_DefaultIsNull()
=> Assert.Null(new AppBarButton().Icon);
=> Assert.Null(new CommandBarButton().Icon);
[Fact]
public void Icon_RoundTrip()
{
var btn = new AppBarButton();
var btn = new CommandBarButton();
var icon = new object();
btn.Icon = icon;
Assert.Same(icon, btn.Icon);
@ -34,72 +34,72 @@ public class AppBarButtonTests : ScopedTestBase
[Fact]
public void IsCompact_DefaultIsFalse()
=> Assert.False(new AppBarButton().IsCompact);
=> Assert.False(new CommandBarButton().IsCompact);
[Fact]
public void IsCompact_RoundTrip()
{
var btn = new AppBarButton { IsCompact = true };
var btn = new CommandBarButton { IsCompact = true };
Assert.True(btn.IsCompact);
}
[Fact]
public void DynamicOverflowOrder_DefaultIsZero()
=> Assert.Equal(0, new AppBarButton().DynamicOverflowOrder);
=> Assert.Equal(0, new CommandBarButton().DynamicOverflowOrder);
[Fact]
public void DynamicOverflowOrder_RoundTrip()
{
var btn = new AppBarButton { DynamicOverflowOrder = 3 };
var btn = new CommandBarButton { DynamicOverflowOrder = 3 };
Assert.Equal(3, btn.DynamicOverflowOrder);
}
[Fact]
public void LabelPosition_DefaultIsBottom()
=> Assert.Equal(CommandBarDefaultLabelPosition.Bottom, new AppBarButton().LabelPosition);
=> Assert.Equal(CommandBarDefaultLabelPosition.Bottom, new CommandBarButton().LabelPosition);
[Fact]
public void LabelPosition_RoundTrip()
{
var btn = new AppBarButton { LabelPosition = CommandBarDefaultLabelPosition.Right };
var btn = new CommandBarButton { LabelPosition = CommandBarDefaultLabelPosition.Right };
Assert.Equal(CommandBarDefaultLabelPosition.Right, btn.LabelPosition);
}
[Fact]
public void IsInOverflow_DefaultIsFalse()
=> Assert.False(new AppBarButton().IsInOverflow);
=> Assert.False(new CommandBarButton().IsInOverflow);
[Fact]
public void IsInOverflow_RoundTrip()
{
var btn = new AppBarButton { IsInOverflow = true };
var btn = new CommandBarButton { IsInOverflow = true };
Assert.True(btn.IsInOverflow);
}
[Fact]
public void ImplementsICommandBarElement()
=> Assert.IsAssignableFrom<ICommandBarElement>(new AppBarButton());
=> Assert.IsAssignableFrom<ICommandBarElement>(new CommandBarButton());
[Fact]
public void ICommandBarElement_IsCompact_ReadWrite()
{
ICommandBarElement elem = new AppBarButton();
ICommandBarElement elem = new CommandBarButton();
elem.IsCompact = true;
Assert.True(elem.IsCompact);
}
[Fact]
public void Command_DefaultIsNull()
=> Assert.Null(new AppBarButton().Command);
=> Assert.Null(new CommandBarButton().Command);
[Fact]
public void CommandParameter_DefaultIsNull()
=> Assert.Null(new AppBarButton().CommandParameter);
=> Assert.Null(new CommandBarButton().CommandParameter);
[Fact]
public void Command_RoundTrip()
{
var btn = new AppBarButton();
var btn = new CommandBarButton();
var cmd = new DelegateCommand(_ => { });
btn.Command = cmd;
Assert.Same(cmd, btn.Command);
@ -108,85 +108,85 @@ public class AppBarButtonTests : ScopedTestBase
[Fact]
public void CommandParameter_RoundTrip()
{
var btn = new AppBarButton { CommandParameter = "param" };
var btn = new CommandBarButton { CommandParameter = "param" };
Assert.Equal("param", btn.CommandParameter);
}
}
public class AppBarToggleButtonTests : ScopedTestBase
public class CommandBarToggleButtonTests : ScopedTestBase
{
[Fact]
public void Label_DefaultIsNull()
=> Assert.Null(new AppBarToggleButton().Label);
=> Assert.Null(new CommandBarToggleButton().Label);
[Fact]
public void Label_RoundTrip()
{
var btn = new AppBarToggleButton { Label = "Bold" };
var btn = new CommandBarToggleButton { Label = "Bold" };
Assert.Equal("Bold", btn.Label);
}
[Fact]
public void Icon_DefaultIsNull()
=> Assert.Null(new AppBarToggleButton().Icon);
=> Assert.Null(new CommandBarToggleButton().Icon);
[Fact]
public void IsCompact_DefaultIsFalse()
=> Assert.False(new AppBarToggleButton().IsCompact);
=> Assert.False(new CommandBarToggleButton().IsCompact);
[Fact]
public void IsCompact_RoundTrip()
{
var btn = new AppBarToggleButton { IsCompact = true };
var btn = new CommandBarToggleButton { IsCompact = true };
Assert.True(btn.IsCompact);
}
[Fact]
public void DynamicOverflowOrder_DefaultIsZero()
=> Assert.Equal(0, new AppBarToggleButton().DynamicOverflowOrder);
=> Assert.Equal(0, new CommandBarToggleButton().DynamicOverflowOrder);
[Fact]
public void DynamicOverflowOrder_RoundTrip()
{
var btn = new AppBarToggleButton { DynamicOverflowOrder = 5 };
var btn = new CommandBarToggleButton { DynamicOverflowOrder = 5 };
Assert.Equal(5, btn.DynamicOverflowOrder);
}
[Fact]
public void LabelPosition_DefaultIsBottom()
=> Assert.Equal(CommandBarDefaultLabelPosition.Bottom, new AppBarToggleButton().LabelPosition);
=> Assert.Equal(CommandBarDefaultLabelPosition.Bottom, new CommandBarToggleButton().LabelPosition);
[Fact]
public void LabelPosition_RoundTrip()
{
var btn = new AppBarToggleButton { LabelPosition = CommandBarDefaultLabelPosition.Collapsed };
var btn = new CommandBarToggleButton { LabelPosition = CommandBarDefaultLabelPosition.Collapsed };
Assert.Equal(CommandBarDefaultLabelPosition.Collapsed, btn.LabelPosition);
}
[Fact]
public void IsInOverflow_DefaultIsFalse()
=> Assert.False(new AppBarToggleButton().IsInOverflow);
=> Assert.False(new CommandBarToggleButton().IsInOverflow);
[Fact]
public void ImplementsICommandBarElement()
=> Assert.IsAssignableFrom<ICommandBarElement>(new AppBarToggleButton());
=> Assert.IsAssignableFrom<ICommandBarElement>(new CommandBarToggleButton());
[Fact]
public void ICommandBarElement_IsCompact_ReadWrite()
{
ICommandBarElement elem = new AppBarToggleButton();
ICommandBarElement elem = new CommandBarToggleButton();
elem.IsCompact = true;
Assert.True(elem.IsCompact);
}
[Fact]
public void Command_DefaultIsNull()
=> Assert.Null(new AppBarToggleButton().Command);
=> Assert.Null(new CommandBarToggleButton().Command);
[Fact]
public void Command_RoundTrip()
{
var btn = new AppBarToggleButton();
var btn = new CommandBarToggleButton();
var cmd = new DelegateCommand(_ => { });
btn.Command = cmd;
Assert.Same(cmd, btn.Command);
@ -195,43 +195,47 @@ public class AppBarToggleButtonTests : ScopedTestBase
[Fact]
public void CommandParameter_RoundTrip()
{
var btn = new AppBarToggleButton { CommandParameter = 42 };
var btn = new CommandBarToggleButton { CommandParameter = 42 };
Assert.Equal(42, btn.CommandParameter);
}
}
public class AppBarSeparatorTests : ScopedTestBase
public class CommandBarSeparatorTests : ScopedTestBase
{
[Fact]
public void IsCompact_DefaultIsFalse()
=> Assert.False(new AppBarSeparator().IsCompact);
=> Assert.False(new CommandBarSeparator().IsCompact);
[Fact]
public void IsCompact_RoundTrip()
{
var sep = new AppBarSeparator { IsCompact = true };
var sep = new CommandBarSeparator { IsCompact = true };
Assert.True(sep.IsCompact);
}
[Fact]
public void IsInOverflow_DefaultIsFalse()
=> Assert.False(new AppBarSeparator().IsInOverflow);
=> Assert.False(new CommandBarSeparator().IsInOverflow);
[Fact]
public void IsInOverflow_RoundTrip()
{
var sep = new AppBarSeparator { IsInOverflow = true };
var sep = new CommandBarSeparator { IsInOverflow = true };
Assert.True(sep.IsInOverflow);
}
[Fact]
public void ImplementsICommandBarElement()
=> Assert.IsAssignableFrom<ICommandBarElement>(new AppBarSeparator());
=> Assert.IsAssignableFrom<ICommandBarElement>(new CommandBarSeparator());
[Fact]
public void DerivesFromSeparator()
=> Assert.IsAssignableFrom<Separator>(new CommandBarSeparator());
[Fact]
public void ICommandBarElement_IsCompact_ReadWrite()
{
ICommandBarElement elem = new AppBarSeparator();
ICommandBarElement elem = new CommandBarSeparator();
elem.IsCompact = true;
Assert.True(elem.IsCompact);
}
@ -517,7 +521,7 @@ public class CommandBarCollectionTests : ScopedTestBase
public void PrimaryCommands_Added_AppearInVisiblePrimary_WhenDynamicOverflowDisabled()
{
var cb = new CommandBar();
var btn = new AppBarButton { Label = "Save" };
var btn = new CommandBarButton { Label = "Save" };
cb.PrimaryCommands!.Add(btn);
Assert.Contains(btn, cb.VisiblePrimaryCommands);
}
@ -530,7 +534,7 @@ public class CommandBarCollectionTests : ScopedTestBase
((INotifyCollectionChanged)cb.VisiblePrimaryCommands).CollectionChanged += (_, _) => notifications++;
cb.PrimaryCommands!.Add(new AppBarButton { Label = "Save" });
cb.PrimaryCommands!.Add(new CommandBarButton { Label = "Save" });
Assert.Equal(2, notifications);
}
@ -539,7 +543,7 @@ public class CommandBarCollectionTests : ScopedTestBase
public void PrimaryCommands_Removed_DisappearsFromVisiblePrimary()
{
var cb = new CommandBar();
var btn = new AppBarButton { Label = "Save" };
var btn = new CommandBarButton { Label = "Save" };
cb.PrimaryCommands!.Add(btn);
cb.PrimaryCommands!.Remove(btn);
Assert.DoesNotContain(btn, cb.VisiblePrimaryCommands);
@ -549,7 +553,7 @@ public class CommandBarCollectionTests : ScopedTestBase
public void SecondaryCommands_Added_AppearInOverflowItems()
{
var cb = new CommandBar();
var btn = new AppBarButton { Label = "Settings" };
var btn = new CommandBarButton { Label = "Settings" };
cb.SecondaryCommands!.Add(btn);
Assert.Contains(btn, cb.OverflowItems);
}
@ -562,7 +566,7 @@ public class CommandBarCollectionTests : ScopedTestBase
((INotifyCollectionChanged)cb.OverflowItems).CollectionChanged += (_, _) => notifications++;
cb.SecondaryCommands!.Add(new AppBarButton { Label = "Settings" });
cb.SecondaryCommands!.Add(new CommandBarButton { Label = "Settings" });
Assert.Equal(2, notifications);
}
@ -571,7 +575,7 @@ public class CommandBarCollectionTests : ScopedTestBase
public void SecondaryCommands_Removed_DisappearsFromOverflowItems()
{
var cb = new CommandBar();
var btn = new AppBarButton { Label = "Settings" };
var btn = new CommandBarButton { Label = "Settings" };
cb.SecondaryCommands!.Add(btn);
cb.SecondaryCommands!.Remove(btn);
Assert.DoesNotContain(btn, cb.OverflowItems);
@ -581,7 +585,7 @@ public class CommandBarCollectionTests : ScopedTestBase
public void HasSecondaryCommands_TrueWhenSecondaryAdded()
{
var cb = new CommandBar();
cb.SecondaryCommands!.Add(new AppBarButton { Label = "Options" });
cb.SecondaryCommands!.Add(new CommandBarButton { Label = "Options" });
Assert.True(cb.HasSecondaryCommands);
}
@ -589,7 +593,7 @@ public class CommandBarCollectionTests : ScopedTestBase
public void HasSecondaryCommands_FalseAfterSecondaryCleared()
{
var cb = new CommandBar();
var btn = new AppBarButton { Label = "Options" };
var btn = new CommandBarButton { Label = "Options" };
cb.SecondaryCommands!.Add(btn);
cb.SecondaryCommands!.Remove(btn);
Assert.False(cb.HasSecondaryCommands);
@ -599,8 +603,8 @@ public class CommandBarCollectionTests : ScopedTestBase
public void OverflowItems_CountMatchesSecondaryCommandCount()
{
var cb = new CommandBar();
cb.SecondaryCommands!.Add(new AppBarButton());
cb.SecondaryCommands!.Add(new AppBarButton());
cb.SecondaryCommands!.Add(new CommandBarButton());
cb.SecondaryCommands!.Add(new CommandBarButton());
Assert.Equal(2, cb.OverflowItems.Count);
}
@ -608,8 +612,8 @@ public class CommandBarCollectionTests : ScopedTestBase
public void VisiblePrimaryCommands_CountMatchesPrimary_WhenDynamicOverflowDisabled()
{
var cb = new CommandBar();
cb.PrimaryCommands!.Add(new AppBarButton());
cb.PrimaryCommands!.Add(new AppBarButton());
cb.PrimaryCommands!.Add(new CommandBarButton());
cb.PrimaryCommands!.Add(new CommandBarButton());
Assert.Equal(2, cb.VisiblePrimaryCommands.Count);
}
@ -617,9 +621,9 @@ public class CommandBarCollectionTests : ScopedTestBase
public void MultiplePrimaryCommands_AllVisibleInOrder()
{
var cb = new CommandBar();
var btn1 = new AppBarButton { Label = "A" };
var btn2 = new AppBarButton { Label = "B" };
var btn3 = new AppBarButton { Label = "C" };
var btn1 = new CommandBarButton { Label = "A" };
var btn2 = new CommandBarButton { Label = "B" };
var btn3 = new CommandBarButton { Label = "C" };
cb.PrimaryCommands!.Add(btn1);
cb.PrimaryCommands!.Add(btn2);
cb.PrimaryCommands!.Add(btn3);
@ -627,19 +631,19 @@ public class CommandBarCollectionTests : ScopedTestBase
}
[Fact]
public void AppBarSeparator_CanBeAddedToPrimaryCommands()
public void CommandBarSeparator_CanBeAddedToPrimaryCommands()
{
var cb = new CommandBar();
var sep = new AppBarSeparator();
var sep = new CommandBarSeparator();
cb.PrimaryCommands!.Add(sep);
Assert.Contains(sep, cb.VisiblePrimaryCommands);
}
[Fact]
public void AppBarToggleButton_CanBeAddedToPrimaryCommands()
public void CommandBarToggleButton_CanBeAddedToPrimaryCommands()
{
var cb = new CommandBar();
var toggle = new AppBarToggleButton { Label = "Bold" };
var toggle = new CommandBarToggleButton { Label = "Bold" };
cb.PrimaryCommands!.Add(toggle);
Assert.Contains(toggle, cb.VisiblePrimaryCommands);
}
@ -651,7 +655,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
public void DefaultLabelPosition_Collapsed_SetsIsCompactOnExistingPrimaryButton()
{
var cb = new CommandBar();
var btn = new AppBarButton();
var btn = new CommandBarButton();
cb.PrimaryCommands!.Add(btn);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed;
@ -663,7 +667,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
public void DefaultLabelPosition_Bottom_ClearsIsCompactOnPrimaryButton()
{
var cb = new CommandBar();
var btn = new AppBarButton();
var btn = new CommandBarButton();
cb.PrimaryCommands!.Add(btn);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed;
@ -676,7 +680,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
public void DefaultLabelPosition_Right_SetsLabelPositionOnPrimaryButton()
{
var cb = new CommandBar();
var btn = new AppBarButton();
var btn = new CommandBarButton();
cb.PrimaryCommands!.Add(btn);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Right;
@ -688,7 +692,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
public void DefaultLabelPosition_Collapsed_SetsLabelPositionOnPrimaryButton()
{
var cb = new CommandBar();
var btn = new AppBarButton();
var btn = new CommandBarButton();
cb.PrimaryCommands!.Add(btn);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed;
@ -700,7 +704,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
public void DefaultLabelPosition_Collapsed_PropagatesIsCompactToToggleButton()
{
var cb = new CommandBar();
var toggle = new AppBarToggleButton();
var toggle = new CommandBarToggleButton();
cb.PrimaryCommands!.Add(toggle);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed;
@ -713,7 +717,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
public void DefaultLabelPosition_Right_PropagatesLabelPositionToToggleButton()
{
var cb = new CommandBar();
var toggle = new AppBarToggleButton();
var toggle = new CommandBarToggleButton();
cb.PrimaryCommands!.Add(toggle);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Right;
@ -725,7 +729,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
public void DefaultLabelPosition_Collapsed_SetsIsCompactOnSeparator()
{
var cb = new CommandBar();
var sep = new AppBarSeparator();
var sep = new CommandBarSeparator();
cb.PrimaryCommands!.Add(sep);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed;
@ -738,7 +742,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
{
var cb = new CommandBar { DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed };
var btn = new AppBarButton();
var btn = new CommandBarButton();
cb.PrimaryCommands!.Add(btn);
Assert.True(btn.IsCompact);
@ -750,7 +754,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
{
var cb = new CommandBar { DefaultLabelPosition = CommandBarDefaultLabelPosition.Right };
var btn = new AppBarButton();
var btn = new CommandBarButton();
cb.PrimaryCommands!.Add(btn);
Assert.Equal(CommandBarDefaultLabelPosition.Right, btn.LabelPosition);
@ -760,7 +764,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
public void DefaultLabelPosition_Collapsed_AppliesToSecondaryCommands()
{
var cb = new CommandBar();
var btn = new AppBarButton();
var btn = new CommandBarButton();
cb.SecondaryCommands!.Add(btn);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed;
@ -772,7 +776,7 @@ public class CommandBarLabelPositionTests : ScopedTestBase
public void DefaultLabelPosition_DoesNotClearLabelText()
{
var cb = new CommandBar();
var btn = new AppBarButton { Label = "Save" };
var btn = new CommandBarButton { Label = "Save" };
cb.PrimaryCommands!.Add(btn);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed;
@ -801,7 +805,7 @@ public class CommandBarOverflowButtonTests : ScopedTestBase
public void OverflowButtonVisibility_Auto_TrueWhenHasSecondaryCommands()
{
var cb = new CommandBar();
cb.SecondaryCommands!.Add(new AppBarButton());
cb.SecondaryCommands!.Add(new CommandBarButton());
Assert.True(cb.IsOverflowButtonVisible);
}
@ -823,7 +827,7 @@ public class CommandBarOverflowButtonTests : ScopedTestBase
public void OverflowButtonVisibility_Collapsed_RemainsFalseEvenWithSecondary()
{
var cb = new CommandBar { OverflowButtonVisibility = CommandBarOverflowButtonVisibility.Collapsed };
cb.SecondaryCommands!.Add(new AppBarButton());
cb.SecondaryCommands!.Add(new CommandBarButton());
Assert.False(cb.IsOverflowButtonVisible);
}
@ -831,7 +835,7 @@ public class CommandBarOverflowButtonTests : ScopedTestBase
public void OverflowButtonVisibility_Auto_FalseAfterSecondaryRemoved()
{
var cb = new CommandBar();
var btn = new AppBarButton();
var btn = new CommandBarButton();
cb.SecondaryCommands!.Add(btn);
Assert.True(cb.IsOverflowButtonVisible);
@ -863,9 +867,9 @@ public class CommandBarItemWidthTests : ScopedTestBase
public void ItemWidthBottom_Controls_HowManyButtonsFit()
{
var cb = CreateWithWidth(300);
cb.SecondaryCommands!.Add(new AppBarButton()); // forces overflow button
cb.SecondaryCommands!.Add(new CommandBarButton()); // forces overflow button
for (int i = 0; i < 4; i++)
cb.PrimaryCommands!.Add(new AppBarButton());
cb.PrimaryCommands!.Add(new CommandBarButton());
cb.IsDynamicOverflowEnabled = true;
Assert.Equal(3, cb.VisiblePrimaryCommands.Count);
@ -877,9 +881,9 @@ public class CommandBarItemWidthTests : ScopedTestBase
{
var cb = CreateWithWidth(300);
cb.ItemWidthBottom = 35;
cb.SecondaryCommands!.Add(new AppBarButton());
cb.SecondaryCommands!.Add(new CommandBarButton());
for (int i = 0; i < 4; i++)
cb.PrimaryCommands!.Add(new AppBarButton());
cb.PrimaryCommands!.Add(new CommandBarButton());
cb.IsDynamicOverflowEnabled = true;
Assert.Equal(4, cb.VisiblePrimaryCommands.Count);
@ -890,9 +894,9 @@ public class CommandBarItemWidthTests : ScopedTestBase
{
var cb = CreateWithWidth(300);
cb.ItemWidthBottom = 260;
cb.SecondaryCommands!.Add(new AppBarButton());
cb.SecondaryCommands!.Add(new CommandBarButton());
for (int i = 0; i < 3; i++)
cb.PrimaryCommands!.Add(new AppBarButton());
cb.PrimaryCommands!.Add(new CommandBarButton());
cb.IsDynamicOverflowEnabled = true;
Assert.Equal(1, cb.VisiblePrimaryCommands.Count);
@ -903,9 +907,9 @@ public class CommandBarItemWidthTests : ScopedTestBase
{
var cb = CreateWithWidth(300);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Right;
cb.SecondaryCommands!.Add(new AppBarButton());
cb.SecondaryCommands!.Add(new CommandBarButton());
for (int i = 0; i < 4; i++)
cb.PrimaryCommands!.Add(new AppBarButton());
cb.PrimaryCommands!.Add(new CommandBarButton());
cb.IsDynamicOverflowEnabled = true;
Assert.Equal(2, cb.VisiblePrimaryCommands.Count);
@ -917,9 +921,9 @@ public class CommandBarItemWidthTests : ScopedTestBase
var cb = CreateWithWidth(300);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Right;
cb.ItemWidthRight = 252; // exactly 1 fits: 252/252=1
cb.SecondaryCommands!.Add(new AppBarButton());
cb.SecondaryCommands!.Add(new CommandBarButton());
for (int i = 0; i < 3; i++)
cb.PrimaryCommands!.Add(new AppBarButton());
cb.PrimaryCommands!.Add(new CommandBarButton());
cb.IsDynamicOverflowEnabled = true;
Assert.Equal(1, cb.VisiblePrimaryCommands.Count);
@ -930,9 +934,9 @@ public class CommandBarItemWidthTests : ScopedTestBase
{
var cb = CreateWithWidth(300);
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Collapsed;
cb.SecondaryCommands!.Add(new AppBarButton());
cb.SecondaryCommands!.Add(new CommandBarButton());
for (int i = 0; i < 4; i++)
cb.PrimaryCommands!.Add(new AppBarButton());
cb.PrimaryCommands!.Add(new CommandBarButton());
cb.IsDynamicOverflowEnabled = true;
Assert.Equal(4, cb.VisiblePrimaryCommands.Count);
@ -945,9 +949,9 @@ public class CommandBarItemWidthTests : ScopedTestBase
cb.ItemWidthBottom = 70;
cb.ItemWidthRight = 102;
cb.ItemWidthCollapsed = 42;
cb.SecondaryCommands!.Add(new AppBarButton());
cb.SecondaryCommands!.Add(new CommandBarButton());
for (int i = 0; i < 4; i++)
cb.PrimaryCommands!.Add(new AppBarButton());
cb.PrimaryCommands!.Add(new CommandBarButton());
cb.DefaultLabelPosition = CommandBarDefaultLabelPosition.Bottom;
cb.IsDynamicOverflowEnabled = true;

16
tests/Avalonia.RenderTests/Controls/CommandBarTests.cs

@ -37,7 +37,7 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
Background = Brushes.LightGray,
PrimaryCommands =
{
new AppBarButton
new CommandBarButton
{
Label = "New",
Icon = new Path
@ -49,7 +49,7 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
Stretch = Stretch.Uniform
}
},
new AppBarButton
new CommandBarButton
{
Label = "Save",
Icon = new Path
@ -61,8 +61,8 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
Stretch = Stretch.Uniform
}
},
new AppBarSeparator(),
new AppBarToggleButton
new CommandBarSeparator(),
new CommandBarToggleButton
{
Label = "Bold",
Icon = new Path
@ -98,7 +98,7 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
OverflowButtonVisibility = CommandBarOverflowButtonVisibility.Collapsed,
PrimaryCommands =
{
new AppBarButton
new CommandBarButton
{
Icon = new Path
{
@ -109,7 +109,7 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
Stretch = Stretch.Uniform
}
},
new AppBarButton
new CommandBarButton
{
Icon = new Path
{
@ -120,8 +120,8 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
Stretch = Stretch.Uniform
}
},
new AppBarSeparator(),
new AppBarToggleButton
new CommandBarSeparator(),
new CommandBarToggleButton
{
IsChecked = true,
Icon = new Path

8
tests/Avalonia.RenderTests/Controls/ContentPageTests.cs

@ -71,7 +71,7 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
Background = Brushes.LightGray,
PrimaryCommands =
{
new AppBarButton
new CommandBarButton
{
Label = "Save",
Icon = new Path
@ -83,8 +83,8 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
Stretch = Stretch.Uniform
}
},
new AppBarSeparator(),
new AppBarToggleButton
new CommandBarSeparator(),
new CommandBarToggleButton
{
Label = "Bold",
Icon = new Path
@ -105,7 +105,7 @@ namespace Avalonia.Direct2D1.RenderTests.Controls
OverflowButtonVisibility = CommandBarOverflowButtonVisibility.Collapsed,
PrimaryCommands =
{
new AppBarButton
new CommandBarButton
{
Icon = new Path
{

Loading…
Cancel
Save