Menu.axaml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <ResourceDictionary xmlns="https://github.com/avaloniaui"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:controls="clr-namespace:SukiUI.Controls"
  4. xmlns:system="clr-namespace:System;assembly=netstandard">
  5. <ControlTheme x:Key="SukiTopLevelMenuItem" TargetType="MenuItem">
  6. <Setter Property="FontWeight" Value="{DynamicResource DefaultDemiBold}" />
  7. <Setter Property="Background" Value="Transparent" />
  8. <Setter Property="Padding" Value="10 0" />
  9. <Setter Property="Template">
  10. <ControlTemplate>
  11. <Border Name="root"
  12. Margin="5,5"
  13. Background="{TemplateBinding Background}"
  14. BorderBrush="{DynamicResource SukiMenuBorderBrush}"
  15. BorderThickness="0"
  16. CornerRadius="8">
  17. <Panel>
  18. <controls:GlassCard CornerRadius="8" Opacity="0" Name="GlassMenuItemBackground" Classes="Control">
  19. <controls:GlassCard.Transitions>
  20. <Transitions>
  21. <DoubleTransition Property="Opacity" Duration="0:0:0.15"></DoubleTransition>
  22. </Transitions>
  23. </controls:GlassCard.Transitions>
  24. </controls:GlassCard>
  25. <ContentPresenter Name="PART_HeaderPresenter"
  26. Margin="{TemplateBinding Padding}"
  27. HorizontalContentAlignment="Left"
  28. VerticalContentAlignment="Center"
  29. Content="{TemplateBinding Header}">
  30. <ContentPresenter.DataTemplates>
  31. <DataTemplate DataType="system:String">
  32. <TextBlock FontWeight="{DynamicResource DefaultDemiBold}" Text="{CompiledBinding}" />
  33. </DataTemplate>
  34. </ContentPresenter.DataTemplates>
  35. </ContentPresenter>
  36. <Popup Name="PART_Popup"
  37. ClipToBounds="True"
  38. IsLightDismissEnabled="True"
  39. IsOpen="{TemplateBinding IsSubMenuOpen,
  40. Mode=TwoWay}"
  41. Opacity="0"
  42. OverlayInputPassThroughElement="{Binding $parent[Menu]}"
  43. Placement="BottomEdgeAlignedLeft">
  44. <LayoutTransformControl Name="PART_LayoutTransform" RenderTransformOrigin="50%, 0%">
  45. <Grid Margin="-12,0,0,0">
  46. <Border Margin="16,8,8,8"
  47. BoxShadow="{DynamicResource SukiPopupShadow}"
  48. CornerRadius="6" />
  49. <Border Name="PART_Border"
  50. Margin="16,8,8,8"
  51. Background="{DynamicResource SukiCardBackground}"
  52. BorderBrush="{DynamicResource SukiMenuBorderBrush}"
  53. BorderThickness="1"
  54. BoxShadow="{DynamicResource SukiPopupShadow}"
  55. ClipToBounds="True"
  56. CornerRadius="6">
  57. <Panel Background="{DynamicResource PopupGradientBrush}">
  58. <ScrollViewer>
  59. <ItemsPresenter Name="PART_ItemsPresenter"
  60. Grid.IsSharedSizeScope="True"
  61. ItemsPanel="{TemplateBinding ItemsPanel}" />
  62. </ScrollViewer>
  63. </Panel>
  64. </Border>
  65. </Grid>
  66. </LayoutTransformControl>
  67. </Popup>
  68. </Panel>
  69. </Border>
  70. </ControlTemplate>
  71. </Setter>
  72. <Style Selector="^:pointerover /template/ controls|GlassCard#GlassMenuItemBackground">
  73. <Setter Property="Opacity" Value="1" />
  74. </Style>
  75. <Style Selector="^:open /template/ LayoutTransformControl#PART_LayoutTransform">
  76. <Style.Animations>
  77. <Animation Easing="{StaticResource MenuEasing}"
  78. FillMode="Forward"
  79. Duration="{StaticResource ShortAnimationDuration}">
  80. <KeyFrame Cue="0%">
  81. <Setter Property="ScaleTransform.ScaleY" Value="0.88" />
  82. <Setter Property="ScaleTransform.ScaleX" Value="0.88" />
  83. <Setter Property="Opacity" Value="0" />
  84. </KeyFrame>
  85. <KeyFrame Cue="100%">
  86. <Setter Property="ScaleTransform.ScaleY" Value="1" />
  87. <Setter Property="ScaleTransform.ScaleX" Value="1" />
  88. <Setter Property="Opacity" Value="1" />
  89. </KeyFrame>
  90. </Animation>
  91. </Style.Animations>
  92. </Style>
  93. </ControlTheme>
  94. <ControlTheme x:Key="SukiMenuStyle" TargetType="Menu">
  95. <Setter Property="Background" Value="Transparent" />
  96. <Setter Property="ItemContainerTheme" Value="{StaticResource SukiTopLevelMenuItem}" />
  97. <Setter Property="Template">
  98. <ControlTemplate>
  99. <LayoutTransformControl Name="PART_LayoutTransform" RenderTransformOrigin="50%, 0%">
  100. <controls:GlassCard Height="45"
  101. Padding="{TemplateBinding Padding}"
  102. BorderBrush="{DynamicResource SukiBorderBrush}"
  103. BorderThickness="0"
  104. CornerRadius="{TemplateBinding CornerRadius}"
  105. IsAnimated="False">
  106. <ItemsPresenter Name="PART_ItemsPresenter"
  107. ItemsPanel="{TemplateBinding ItemsPanel}"
  108. KeyboardNavigation.TabNavigation="Continue" />
  109. </controls:GlassCard>
  110. </LayoutTransformControl>
  111. </ControlTemplate>
  112. </Setter>
  113. <Style Selector="^[IsEnabled=True] /template/ LayoutTransformControl#PART_LayoutTransform">
  114. <Style.Animations>
  115. <Animation Easing="{StaticResource MenuEasing}"
  116. FillMode="Forward"
  117. Duration="{StaticResource MediumAnimationDuration}">
  118. <KeyFrame Cue="0%">
  119. <Setter Property="ScaleTransform.ScaleY" Value="0.92" />
  120. <Setter Property="ScaleTransform.ScaleX" Value="0.92" />
  121. <Setter Property="Opacity" Value="0" />
  122. <Setter Property="IsVisible" Value="True" />
  123. </KeyFrame>
  124. <KeyFrame Cue="100%">
  125. <Setter Property="ScaleTransform.ScaleY" Value="1" />
  126. <Setter Property="ScaleTransform.ScaleX" Value="1" />
  127. <Setter Property="Opacity" Value="1" />
  128. </KeyFrame>
  129. </Animation>
  130. </Style.Animations>
  131. </Style>
  132. <Style Selector="^[IsEnabled=False] /template/ LayoutTransformControl#PART_LayoutTransform">
  133. <Style.Animations>
  134. <Animation Easing="{StaticResource MenuEasing}"
  135. FillMode="Forward"
  136. Duration="{StaticResource MediumAnimationDuration}">
  137. <KeyFrame Cue="0%">
  138. <Setter Property="ScaleTransform.ScaleY" Value="1" />
  139. <Setter Property="ScaleTransform.ScaleX" Value="1" />
  140. <Setter Property="Opacity" Value="1" />
  141. </KeyFrame>
  142. <KeyFrame Cue="100%">
  143. <Setter Property="ScaleTransform.ScaleY" Value="0.9" />
  144. <Setter Property="ScaleTransform.ScaleX" Value="0.9" />
  145. <Setter Property="Opacity" Value="0" />
  146. <Setter Property="IsVisible" Value="False" />
  147. </KeyFrame>
  148. </Animation>
  149. </Style.Animations>
  150. </Style>
  151. </ControlTheme>
  152. <ControlTheme x:Key="{x:Type Menu}"
  153. BasedOn="{StaticResource SukiMenuStyle}"
  154. TargetType="Menu" />
  155. </ResourceDictionary>