CommandBarKeyboardPage.xaml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <UserControl xmlns="https://github.com/avaloniaui"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. x:Class="ControlCatalog.Pages.CommandBarKeyboardPage">
  4. <UserControl.Resources>
  5. <StreamGeometry x:Key="AddIcon">M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z</StreamGeometry>
  6. <StreamGeometry x:Key="SaveIcon">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</StreamGeometry>
  7. <StreamGeometry x:Key="BoldIcon">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</StreamGeometry>
  8. <StreamGeometry x:Key="ShareIcon">M18,16.08C17.24,16.08 16.56,16.38 16.04,16.85L8.91,12.7C8.96,12.47 9,12.24 9,12C9,11.76 8.96,11.53 8.91,11.3L15.96,7.19C16.5,7.69 17.21,8 18,8A3,3 0 0,0 21,5A3,3 0 0,0 18,2A3,3 0 0,0 15,5C15,5.24 15.04,5.47 15.09,5.7L8.04,9.81C7.5,9.31 6.79,9 6,9A3,3 0 0,0 3,12A3,3 0 0,0 6,15C6.79,15 7.5,14.69 8.04,14.19L15.16,18.34C15.11,18.55 15.08,18.77 15.08,19C15.08,20.61 16.39,21.91 18,21.91C19.61,21.91 20.92,20.61 20.92,19C20.92,17.39 19.61,16.08 18,16.08Z</StreamGeometry>
  9. <StreamGeometry x:Key="DeleteIcon">M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z</StreamGeometry>
  10. </UserControl.Resources>
  11. <DockPanel>
  12. <ScrollViewer DockPanel.Dock="Right" Width="240">
  13. <StackPanel Margin="12" Spacing="8">
  14. <TextBlock Text="How to test" FontWeight="SemiBold" FontSize="16"
  15. Foreground="{DynamicResource SystemControlHighlightAccentBrush}" />
  16. <TextBlock FontSize="12" Opacity="0.7" TextWrapping="Wrap"
  17. Text="1. Click &quot;Open overflow&quot; below, or click the ··· button with the mouse." />
  18. <TextBlock FontSize="12" Opacity="0.7" TextWrapping="Wrap"
  19. Text="2. Use Up/Down arrow keys to navigate. Focus wraps from last to first and back." />
  20. <TextBlock FontSize="12" Opacity="0.7" TextWrapping="Wrap"
  21. Text="3. The separator and the disabled Delete item are skipped during navigation." />
  22. <TextBlock FontSize="12" Opacity="0.7" TextWrapping="Wrap"
  23. Text="4. Press Escape to close. Focus returns to the ··· button." />
  24. <TextBlock FontSize="12" Opacity="0.7" TextWrapping="Wrap"
  25. Text="5. You can also Tab into the CommandBar. Focus walks through primary items and the ··· button in order." />
  26. <Separator />
  27. <Button Content="Open overflow"
  28. HorizontalAlignment="Stretch"
  29. Click="OnOpenOverflow" />
  30. <Button Content="Clear Log"
  31. HorizontalAlignment="Stretch"
  32. Click="OnClearLog" />
  33. <Separator />
  34. <TextBlock Text="About" FontWeight="SemiBold" />
  35. <TextBlock FontSize="12" Opacity="0.7" TextWrapping="Wrap"
  36. Text="The focus log updates as keyboard navigation moves between overflow items. Separators and disabled items are excluded from the cycle." />
  37. </StackPanel>
  38. </ScrollViewer>
  39. <Border DockPanel.Dock="Right" Width="1"
  40. Background="{DynamicResource SystemControlForegroundBaseMediumLowBrush}" />
  41. <ScrollViewer>
  42. <StackPanel Spacing="16" Margin="12,12,12,0">
  43. <TextBlock Classes="h2">Keyboard navigation in the overflow popup: Up/Down to move, Home/End to jump, Escape to close.</TextBlock>
  44. <CommandBar x:Name="DemoBar">
  45. <CommandBar.PrimaryCommands>
  46. <CommandBarButton Label="New">
  47. <CommandBarButton.Icon><PathIcon Data="{StaticResource AddIcon}" /></CommandBarButton.Icon>
  48. </CommandBarButton>
  49. <CommandBarButton Label="Save">
  50. <CommandBarButton.Icon><PathIcon Data="{StaticResource SaveIcon}" /></CommandBarButton.Icon>
  51. </CommandBarButton>
  52. </CommandBar.PrimaryCommands>
  53. <CommandBar.SecondaryCommands>
  54. <CommandBarButton x:Name="BtnCopy" Label="Copy" />
  55. <CommandBarButton x:Name="BtnPaste" Label="Paste" />
  56. <CommandBarToggleButton x:Name="BtnBold" Label="Bold">
  57. <CommandBarToggleButton.Icon><PathIcon Data="{StaticResource BoldIcon}" /></CommandBarToggleButton.Icon>
  58. </CommandBarToggleButton>
  59. <CommandBarSeparator />
  60. <CommandBarButton x:Name="BtnShare" Label="Share">
  61. <CommandBarButton.Icon><PathIcon Data="{StaticResource ShareIcon}" /></CommandBarButton.Icon>
  62. </CommandBarButton>
  63. <CommandBarButton x:Name="BtnDelete" Label="Delete" IsEnabled="False">
  64. <CommandBarButton.Icon><PathIcon Data="{StaticResource DeleteIcon}" /></CommandBarButton.Icon>
  65. </CommandBarButton>
  66. <CommandBarButton x:Name="BtnExport" Label="Export" />
  67. </CommandBar.SecondaryCommands>
  68. </CommandBar>
  69. <!-- Keyboard shortcuts reference -->
  70. <Border BorderBrush="{DynamicResource SystemControlForegroundBaseMediumLowBrush}"
  71. BorderThickness="1"
  72. CornerRadius="6"
  73. Padding="10">
  74. <StackPanel Spacing="6">
  75. <TextBlock Text="Keyboard shortcuts" FontWeight="SemiBold" />
  76. <Grid ColumnDefinitions="80,*" RowDefinitions="Auto,Auto,Auto,Auto,Auto">
  77. <TextBlock Grid.Row="0" Grid.Column="0" FontFamily="Consolas,Menlo,monospace" FontSize="12" Text="Down" />
  78. <TextBlock Grid.Row="0" Grid.Column="1" FontSize="12" Opacity="0.7" Text="Next item (wraps to first)" />
  79. <TextBlock Grid.Row="1" Grid.Column="0" FontFamily="Consolas,Menlo,monospace" FontSize="12" Text="Up" />
  80. <TextBlock Grid.Row="1" Grid.Column="1" FontSize="12" Opacity="0.7" Text="Previous item (wraps to last)" />
  81. <TextBlock Grid.Row="2" Grid.Column="0" FontFamily="Consolas,Menlo,monospace" FontSize="12" Text="Home" />
  82. <TextBlock Grid.Row="2" Grid.Column="1" FontSize="12" Opacity="0.7" Text="First item" />
  83. <TextBlock Grid.Row="3" Grid.Column="0" FontFamily="Consolas,Menlo,monospace" FontSize="12" Text="End" />
  84. <TextBlock Grid.Row="3" Grid.Column="1" FontSize="12" Opacity="0.7" Text="Last item" />
  85. <TextBlock Grid.Row="4" Grid.Column="0" FontFamily="Consolas,Menlo,monospace" FontSize="12" Text="Escape" />
  86. <TextBlock Grid.Row="4" Grid.Column="1" FontSize="12" Opacity="0.7" Text="Close menu, focus returns to ··· button" />
  87. </Grid>
  88. </StackPanel>
  89. </Border>
  90. <!-- Focus log -->
  91. <Border BorderBrush="{DynamicResource SystemControlForegroundBaseMediumLowBrush}"
  92. BorderThickness="1"
  93. CornerRadius="6"
  94. Padding="10">
  95. <StackPanel Spacing="6">
  96. <TextBlock Text="Focus log" FontWeight="SemiBold" />
  97. <TextBlock x:Name="FocusLogText"
  98. FontFamily="Consolas, Menlo, monospace"
  99. FontSize="12"
  100. TextWrapping="Wrap"
  101. MinHeight="120"
  102. Opacity="0.8"
  103. Text="Open the overflow menu and use keyboard navigation." />
  104. </StackPanel>
  105. </Border>
  106. </StackPanel>
  107. </ScrollViewer>
  108. </DockPanel>
  109. </UserControl>