HamburgerMenu.xaml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <Styles xmlns="https://github.com/avaloniaui"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:catalog="using:ControlSamples">
  4. <Design.PreviewWith>
  5. <Border Width="400"
  6. Height="150">
  7. <catalog:HamburgerMenu>
  8. <FlyoutBase.AttachedFlyout>
  9. <Flyout>
  10. <TextBox Text="Hello World" />
  11. </Flyout>
  12. </FlyoutBase.AttachedFlyout>
  13. <TabItem Header="Item1" IsSelected="True">
  14. <UserControl>
  15. <Border Height="400" Background="Green" />
  16. </UserControl>
  17. </TabItem>
  18. <TabItem Header="Item2" />
  19. </catalog:HamburgerMenu>
  20. </Border>
  21. </Design.PreviewWith>
  22. <Styles.Resources>
  23. <x:Double x:Key="PaneCompactWidth">40</x:Double>
  24. <x:Double x:Key="PaneExpandWidth">200</x:Double>
  25. <x:Double x:Key="HeaderHeight">36</x:Double>
  26. <x:Double x:Key="NavigationItemHeight">36</x:Double>
  27. <x:Double x:Key="HamburgerMenuButtonHeight">32</x:Double>
  28. <Thickness x:Key="HeaderMarginCollapsedPane">12,0,0,0</Thickness>
  29. <Thickness x:Key="HeaderMarginExpandedPane">52,0,0,0</Thickness>
  30. <Thickness x:Key="HeaderMarginExpandedOverlayPane">212,0,0,0</Thickness>
  31. <BoxShadows x:Key="NavigationItemShadow">1 1 1 1 #2000, 0 0 1 1 #2fff</BoxShadows>
  32. <BoxShadows x:Key="NavigationContentShadow">0 0 1 1 #2000</BoxShadows>
  33. </Styles.Resources>
  34. <!-- HamburgerMenu -->
  35. <Style Selector="catalog|HamburgerMenu">
  36. <Setter Property="Padding" Value="12 8 4 0" />
  37. <Setter Property="PaneBackground" Value="{DynamicResource SystemChromeMediumColor}" />
  38. <Setter Property="Background" Value="{DynamicResource SystemChromeMediumColor}" />
  39. <Setter Property="ContentBackground" Value="{DynamicResource SystemAltHighColor}" />
  40. <Setter Property="Template">
  41. <ControlTemplate>
  42. <Panel Background="{TemplateBinding PaneBackground}">
  43. <SplitView x:Name="PART_NavigationPane"
  44. CompactPaneLength="{StaticResource PaneCompactWidth}"
  45. DisplayMode="Inline"
  46. IsPaneOpen="True"
  47. OpenPaneLength="{StaticResource PaneExpandWidth}">
  48. <SplitView.Pane>
  49. <Grid Margin="0,0,1,5" RowDefinitions="Auto, *, Auto">
  50. <Panel Height="{StaticResource HeaderHeight}" />
  51. <ScrollViewer x:Name="PART_ScrollViewer"
  52. Grid.Row="1"
  53. HorizontalAlignment="Stretch"
  54. HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
  55. VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}">
  56. <ItemsPresenter Name="PART_ItemsPresenter"
  57. HorizontalAlignment="Stretch"
  58. ItemTemplate="{TemplateBinding ItemTemplate}"
  59. Items="{TemplateBinding Items}"
  60. ItemsPanel="{TemplateBinding ItemsPanel}">
  61. <ItemsPresenter.ItemsPanel>
  62. <ItemsPanelTemplate>
  63. <StackPanel x:Name="HamburgerItemsPanel"
  64. Margin="0,2" Orientation="Vertical" />
  65. </ItemsPanelTemplate>
  66. </ItemsPresenter.ItemsPanel>
  67. </ItemsPresenter>
  68. </ScrollViewer>
  69. <Button x:Name="SettingsButton"
  70. Grid.Row="2"
  71. Classes="NavigationButton"
  72. Content="Settings"
  73. Flyout="{TemplateBinding (FlyoutBase.AttachedFlyout)}"
  74. IsVisible="{Binding $parent[TabControl].(FlyoutBase.AttachedFlyout), Converter={x:Static ObjectConverters.IsNotNull}}" />
  75. </Grid>
  76. </SplitView.Pane>
  77. <SplitView.Content>
  78. <DockPanel>
  79. <Border Height="{StaticResource HeaderHeight}" DockPanel.Dock="Top">
  80. <TextBlock x:Name="HeaderHolder"
  81. VerticalAlignment="Center"
  82. Classes="h1"
  83. Text="{Binding $parent[TabControl].SelectedItem.Header, FallbackValue=''}">
  84. <TextBlock.Transitions>
  85. <Transitions>
  86. <ThicknessTransition Easing="{StaticResource SplitViewPaneAnimationEasing}"
  87. Property="Margin"
  88. Duration="{StaticResource SplitViewPaneAnimationCloseDuration}" />
  89. </Transitions>
  90. </TextBlock.Transitions>
  91. </TextBlock>
  92. </Border>
  93. <Border x:Name="BackgroundBorder">
  94. <Border.Transitions>
  95. <Transitions>
  96. <CornerRadiusTransition Property="CornerRadius" Duration="{StaticResource SplitViewPaneAnimationCloseDuration}" />
  97. </Transitions>
  98. </Border.Transitions>
  99. <ScrollViewer x:Name="HamburgerContentScroller"
  100. HorizontalScrollBarVisibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(ScrollViewer.HorizontalScrollBarVisibility)}"
  101. VerticalScrollBarVisibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedItem.(ScrollViewer.VerticalScrollBarVisibility)}">
  102. <ContentPresenter Name="PART_SelectedContentHost"
  103. Background="Transparent"
  104. Padding="{TemplateBinding Padding}"
  105. Content="{TemplateBinding SelectedContent}"
  106. ContentTemplate="{TemplateBinding SelectedContentTemplate}" />
  107. </ScrollViewer>
  108. </Border>
  109. </DockPanel>
  110. </SplitView.Content>
  111. </SplitView>
  112. <ToggleButton x:Name="HamburgerMenuButton"
  113. Width="{StaticResource PaneCompactWidth}"
  114. Height="{StaticResource HamburgerMenuButtonHeight}"
  115. Margin="4,2,0,0"
  116. Padding="0"
  117. HorizontalAlignment="Left"
  118. VerticalAlignment="Top"
  119. HorizontalContentAlignment="Center"
  120. Classes="NavigationButton"
  121. CornerRadius="4"
  122. IsChecked="{Binding #PART_NavigationPane.IsPaneOpen, Mode=TwoWay}">
  123. <PathIcon Data="M3 17h18a1 1 0 0 1 .117 1.993L21 19H3a1 1 0 0 1-.117-1.993L3 17h18H3Zm0-6 18-.002a1 1 0 0 1 .117 1.993l-.117.007L3 13a1 1 0 0 1-.117-1.993L3 11l18-.002L3 11Zm0-6h18a1 1 0 0 1 .117 1.993L21 7H3a1 1 0 0 1-.117-1.993L3 5h18H3Z" Foreground="{TemplateBinding Foreground}" />
  124. </ToggleButton>
  125. </Panel>
  126. </ControlTemplate>
  127. </Setter>
  128. </Style>
  129. <Style Selector="catalog|HamburgerMenu /template/ SplitView TextBlock#HeaderHolder">
  130. <Setter Property="Margin" Value="{StaticResource HeaderMarginExpandedPane}" />
  131. </Style>
  132. <Style Selector="catalog|HamburgerMenu /template/ SplitView[IsPaneOpen=True] TextBlock#HeaderHolder">
  133. <Setter Property="Margin" Value="{StaticResource HeaderMarginCollapsedPane}" />
  134. </Style>
  135. <Style Selector="catalog|HamburgerMenu /template/ SplitView[DisplayMode=Overlay][IsPaneOpen=True] TextBlock#HeaderHolder">
  136. <Setter Property="Margin" Value="{StaticResource HeaderMarginExpandedOverlayPane}" />
  137. </Style>
  138. <Style Selector="catalog|HamburgerMenu /template/ SplitView">
  139. <Setter Property="PaneBackground" Value="Transparent" />
  140. </Style>
  141. <Style Selector="catalog|HamburgerMenu /template/ SplitView[DisplayMode=Overlay]">
  142. <Setter Property="PaneBackground" Value="{TemplateBinding PaneBackground}" />
  143. </Style>
  144. <Style Selector="catalog|HamburgerMenu /template/ SplitView[DisplayMode=Overlay]">
  145. <Setter Property="Background" Value="{Binding $parent[TabControl].ContentBackground}" />
  146. </Style>
  147. <Style Selector="catalog|HamburgerMenu /template/ SplitView[DisplayMode=Inline] Border#BackgroundBorder">
  148. <Setter Property="Background" Value="{Binding $parent[TabControl].ContentBackground}" />
  149. <Setter Property="BoxShadow" Value="{StaticResource NavigationContentShadow}" />
  150. </Style>
  151. <Style Selector="catalog|HamburgerMenu /template/ SplitView[DisplayMode=Inline][IsPaneOpen=True] Border#BackgroundBorder">
  152. <Setter Property="CornerRadius" Value="8 0 0 0" />
  153. </Style>
  154. <!-- HamburgerMenu TabItem -->
  155. <Style Selector="catalog|HamburgerMenu > TabItem, :is(Button).NavigationButton">
  156. <Setter Property="HorizontalContentAlignment" Value="Stretch" />
  157. <Setter Property="VerticalContentAlignment" Value="Center" />
  158. <Setter Property="HorizontalAlignment" Value="Stretch" />
  159. <Setter Property="VerticalAlignment" Value="Stretch" />
  160. <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
  161. <Setter Property="FontWeight" Value="Normal" />
  162. <Setter Property="MinHeight" Value="0" />
  163. <Setter Property="Height" Value="{StaticResource NavigationItemHeight}" />
  164. <Setter Property="Background" Value="Transparent" />
  165. <Setter Property="Padding" Value="12,0,4,0" />
  166. <Setter Property="Margin" Value="4,0,8,0" />
  167. <Setter Property="CornerRadius" Value="8" />
  168. <Setter Property="ClipToBounds" Value="False" />
  169. </Style>
  170. <Style Selector="catalog|HamburgerMenu > TabItem">
  171. <Setter Property="Template">
  172. <ControlTemplate>
  173. <Border Name="PART_LayoutRoot"
  174. HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
  175. Background="{TemplateBinding Background}"
  176. BorderBrush="{TemplateBinding BorderBrush}"
  177. BorderThickness="{TemplateBinding BorderThickness}"
  178. CornerRadius="{TemplateBinding CornerRadius}">
  179. <Panel>
  180. <Border Name="PART_SelectedPipe"
  181. Width="{DynamicResource TabItemPipeThickness}"
  182. Height="{DynamicResource TabItemVerticalPipeHeight}"
  183. Margin="6,0,0,0"
  184. HorizontalAlignment="Left"
  185. VerticalAlignment="Center"
  186. Background="{DynamicResource TabItemHeaderSelectedPipeFill}" />
  187. <ContentPresenter Name="PART_ContentPresenter"
  188. Padding="{TemplateBinding Padding}"
  189. HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
  190. VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  191. Content="{TemplateBinding Header}"
  192. ContentTemplate="{TemplateBinding HeaderTemplate}"
  193. TextBlock.FontFamily="{TemplateBinding FontFamily}"
  194. TextBlock.FontSize="{TemplateBinding FontSize}"
  195. TextBlock.FontWeight="{TemplateBinding FontWeight}" />
  196. </Panel>
  197. </Border>
  198. </ControlTemplate>
  199. </Setter>
  200. </Style>
  201. <Style Selector=":is(Button).NavigationButton">
  202. <Setter Property="Template">
  203. <ControlTemplate>
  204. <ContentPresenter Name="PART_ContentPresenter"
  205. Padding="{TemplateBinding Padding}"
  206. HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
  207. VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
  208. Background="{TemplateBinding Background}"
  209. BorderBrush="{TemplateBinding BorderBrush}"
  210. BorderThickness="{TemplateBinding BorderThickness}"
  211. Content="{TemplateBinding Content}"
  212. ContentTemplate="{TemplateBinding ContentTemplate}"
  213. CornerRadius="{TemplateBinding CornerRadius}"
  214. TextBlock.FontFamily="{TemplateBinding FontFamily}"
  215. TextBlock.FontSize="{TemplateBinding FontSize}"
  216. TextBlock.FontWeight="{TemplateBinding FontWeight}" />
  217. </ControlTemplate>
  218. </Setter>
  219. </Style>
  220. <Style Selector="catalog|HamburgerMenu > TabItem /template/ Border#PART_LayoutRoot, :is(Button).NavigationButton /template/ ContentPresenter">
  221. <Setter Property="Border.Background" Value="Transparent" />
  222. <Setter Property="TextBlock.Foreground" Value="{DynamicResource SystemBaseHighColor}" />
  223. </Style>
  224. <Style Selector="catalog|HamburgerMenu > TabItem:pointerover /template/ Border#PART_LayoutRoot, :is(Button).NavigationButton:pointerover /template/ ContentPresenter">
  225. <Setter Property="Border.Background" Value="{DynamicResource SystemChromeLowColor}" />
  226. <Setter Property="Border.BoxShadow" Value="{StaticResource NavigationItemShadow}" />
  227. <Setter Property="TextBlock.Foreground" Value="{DynamicResource TabItemHeaderForegroundUnselectedPointerOver}" />
  228. </Style>
  229. <Style Selector="catalog|HamburgerMenu > TabItem:pressed /template/ Border#PART_LayoutRoot, :is(Button).NavigationButton:pressed /template/ ContentPresenter">
  230. <Setter Property="Border.Background" Value="{DynamicResource SystemChromeLowColor}" />
  231. <Setter Property="Border.BoxShadow" Value="{StaticResource NavigationItemShadow}" />
  232. <Setter Property="TextBlock.Foreground" Value="{DynamicResource TabItemHeaderForegroundUnselectedPressed}" />
  233. </Style>
  234. <Style Selector=":is(Button).NavigationButton:pressed">
  235. <Setter Property="RenderTransform" Value="none" />
  236. </Style>
  237. </Styles>