MenuItem.axaml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <ResourceDictionary xmlns="https://github.com/avaloniaui"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:content="clr-namespace:SukiUI.Content"
  4. xmlns:controls="clr-namespace:SukiUI.Controls"
  5. xmlns:converters="clr-namespace:Avalonia.Controls.Converters;assembly=Avalonia.Controls"
  6. xmlns:system="clr-namespace:System;assembly=netstandard">
  7. <converters:PlatformKeyGestureConverter x:Key="KeyGestureConverter" />
  8. <ControlTheme x:Key="SukiMenuItemStyle" TargetType="MenuItem">
  9. <Setter Property="Background" Value="{DynamicResource SukiBackground}" />
  10. <Setter Property="BorderThickness" Value="1.5" />
  11. <Setter Property="FontSize" Value="14" />
  12. <Setter Property="Margin" Value="0" />
  13. <Setter Property="Foreground" Value="{DynamicResource SukiText}" />
  14. <Setter Property="Template">
  15. <ControlTemplate>
  16. <Border Name="root"
  17. Background="{TemplateBinding Background}"
  18. BorderBrush="{TemplateBinding BorderBrush}"
  19. ClipToBounds="True">
  20. <Panel>
  21. <DockPanel Margin="5,10">
  22. <ContentPresenter Name="PART_Icon"
  23. Width="15"
  24. Height="15"
  25. Margin="5,0"
  26. HorizontalAlignment="Center"
  27. VerticalAlignment="Center"
  28. Content="{TemplateBinding Icon}"
  29. DockPanel.Dock="Left" />
  30. <Rectangle Width="1"
  31. Margin="5,-2"
  32. DockPanel.Dock="Left"
  33. Fill="{DynamicResource SukiLightBorderBrush}" />
  34. <PathIcon Name="PART_RightArrow"
  35. Classes="Flippable"
  36. Width="8"
  37. Height="8"
  38. Margin="5,0,10,0"
  39. HorizontalAlignment="Right"
  40. VerticalAlignment="Center"
  41. Data="{x:Static content:Icons.ChevronRight}"
  42. DockPanel.Dock="Right"
  43. Foreground="{DynamicResource SukiText}" />
  44. <ContentPresenter Name="PART_HeaderPresenter"
  45. Margin="5,0"
  46. HorizontalAlignment="Left"
  47. VerticalAlignment="Center"
  48. Content="{TemplateBinding Header}">
  49. <ContentPresenter.DataTemplates>
  50. <DataTemplate DataType="system:String">
  51. <TextBlock FontWeight="{DynamicResource DefaultDemiBold}" Text="{Binding}" />
  52. </DataTemplate>
  53. </ContentPresenter.DataTemplates>
  54. </ContentPresenter>
  55. </DockPanel>
  56. <TextBlock Name="PART_InputGestureText"
  57. VerticalAlignment="Center"
  58. Text="{TemplateBinding InputGesture,
  59. Converter={StaticResource KeyGestureConverter}}" />
  60. <Popup Name="PART_Popup"
  61. ClipToBounds="True"
  62. HorizontalOffset="-25"
  63. IsLightDismissEnabled="False"
  64. IsOpen="{TemplateBinding IsSubMenuOpen,
  65. Mode=TwoWay}"
  66. Opacity="0"
  67. OverlayInputPassThroughElement="{Binding $parent[Menu]}"
  68. Placement="RightEdgeAlignedTop"
  69. VerticalOffset="-1">
  70. <LayoutTransformControl Name="PART_LayoutTransform" RenderTransformOrigin="0%, 0%">
  71. <Panel Margin="0,-8,0,0">
  72. <Border Margin="16,8,8,8"
  73. BoxShadow="{DynamicResource SukiPopupShadow}"
  74. CornerRadius="6" />
  75. <Border Name="PART_Border"
  76. Margin="16,8,8,8"
  77. Background="{DynamicResource SukiCardBackground}"
  78. BorderBrush="{DynamicResource SukiMenuBorderBrush}"
  79. BorderThickness="1"
  80. BoxShadow="{DynamicResource SukiPopupShadow}"
  81. ClipToBounds="True"
  82. CornerRadius="5">
  83. <Panel Background="{DynamicResource PopupGradientBrush}">
  84. <ScrollViewer>
  85. <ItemsPresenter Name="PART_ItemsPresenter" ItemsPanel="{TemplateBinding ItemsPanel}" />
  86. </ScrollViewer>
  87. </Panel>
  88. </Border>
  89. </Panel>
  90. </LayoutTransformControl>
  91. </Popup>
  92. </Panel>
  93. </Border>
  94. </ControlTemplate>
  95. </Setter>
  96. <Style Selector="^:pointerover">
  97. <Setter Property="Background" Value="{DynamicResource SukiLightBorderBrush}" />
  98. </Style>
  99. <Style Selector="^:open /template/ LayoutTransformControl#PART_LayoutTransform">
  100. <Style.Animations>
  101. <Animation Easing="{StaticResource MenuEasing}"
  102. FillMode="Forward"
  103. Duration="{StaticResource ShortAnimationDuration}">
  104. <KeyFrame Cue="0%">
  105. <Setter Property="ScaleTransform.ScaleY" Value="0.92" />
  106. <Setter Property="ScaleTransform.ScaleX" Value="0.92" />
  107. <Setter Property="Opacity" Value="0" />
  108. </KeyFrame>
  109. <KeyFrame Cue="100%">
  110. <Setter Property="ScaleTransform.ScaleY" Value="1" />
  111. <Setter Property="ScaleTransform.ScaleX" Value="1" />
  112. <Setter Property="Opacity" Value="1" />
  113. </KeyFrame>
  114. </Animation>
  115. </Style.Animations>
  116. </Style>
  117. <Style Selector="^:selected /template/ Border#root">
  118. <Setter Property="Background" Value="{DynamicResource SukiLightBorderBrush}" />
  119. <Setter Property="BorderBrush" Value="{DynamicResource SukiLightBorderBrush}" />
  120. </Style>
  121. <Style Selector="^:disabled">
  122. <Setter Property="Opacity" Value="{DynamicResource ThemeDisabledOpacity}" />
  123. </Style>
  124. <Style Selector="^ /template/ ContentPresenter#PART_Icon">
  125. <Setter Property="Width" Value="24" />
  126. <Setter Property="Height" Value="24" />
  127. </Style>
  128. <Style Selector="^:not(.Menu):disabled">
  129. <Setter Property="Opacity" Value="0.56" />
  130. </Style>
  131. <Style Selector="^:empty /template/ PathIcon#PART_RightArrow">
  132. <Setter Property="IsVisible" Value="False" />
  133. </Style>
  134. <Style Selector="^:separator">
  135. <Setter Property="Template">
  136. <ControlTemplate>
  137. <Separator Margin="0"/>
  138. </ControlTemplate>
  139. </Setter>
  140. </Style>
  141. <Style Selector="^[FlowDirection=RightToLeft] /template/ Popup#PART_Popup">
  142. <Setter Property="HorizontalOffset" Value="25"/>
  143. </Style>
  144. </ControlTheme>
  145. <ControlTheme x:Key="{x:Type MenuItem}"
  146. BasedOn="{StaticResource SukiMenuItemStyle}"
  147. TargetType="MenuItem" />
  148. </ResourceDictionary>