MenuItem.xaml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. mc:Ignorable="d">
  7. <ControlTemplate x:Key="SubMenuItem" TargetType="{x:Type MenuItem}">
  8. <ControlTemplate.Resources>
  9. <Storyboard x:Key="SubMenuOnMouseOver">
  10. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HighLight">
  11. <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
  12. <SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="1" KeySpline="0,0,1,0"/>
  13. </DoubleAnimationUsingKeyFrames>
  14. </Storyboard>
  15. <Storyboard x:Key="SubMenuOnMouseOut">
  16. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="HighLight">
  17. <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
  18. <SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="0" KeySpline="0,0,0,1"/>
  19. </DoubleAnimationUsingKeyFrames>
  20. </Storyboard>
  21. </ControlTemplate.Resources>
  22. <Grid SnapsToDevicePixels="true" Margin="0,3">
  23. <Rectangle x:Name="HighLight" Margin="-2,-2,-3,2" Fill="{DynamicResource Color_BG_SubMenu_OnMouseOver}" Opacity="0"/>
  24. <ContentPresenter x:Name="contentPresenter" Margin="16,0" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" RecognizesAccessKey="True" Grid.Column="0">
  25. </ContentPresenter>
  26. <Rectangle Height="1" VerticalAlignment="Bottom" Fill="{DynamicResource Color_BG_SubMenu_LineHighlight}">
  27. <Rectangle.OpacityMask>
  28. <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
  29. <GradientStop Offset="0"/>
  30. <GradientStop Offset="1"/>
  31. <GradientStop Color="White" Offset="0.2"/>
  32. <GradientStop Color="White" Offset="0.8"/>
  33. </LinearGradientBrush>
  34. </Rectangle.OpacityMask>
  35. </Rectangle>
  36. <Rectangle Height="1" Margin="0,0,0,2" VerticalAlignment="Bottom" StrokeThickness="2" Fill="{DynamicResource Color_BG_SubMenu_LineShadow}">
  37. <Rectangle.OpacityMask>
  38. <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
  39. <GradientStop Offset="0"/>
  40. <GradientStop Offset="1"/>
  41. <GradientStop Color="White" Offset="0.2"/>
  42. <GradientStop Color="White" Offset="0.8"/>
  43. </LinearGradientBrush>
  44. </Rectangle.OpacityMask>
  45. </Rectangle>
  46. </Grid>
  47. <ControlTemplate.Triggers>
  48. <Trigger Property="Icon" Value="{x:Null}"/>
  49. <Trigger Property="IsChecked" Value="true"/>
  50. <Trigger Property="IsHighlighted" Value="true">
  51. <Trigger.ExitActions>
  52. <BeginStoryboard x:Name="SubMenuOnMouseOut_BeginStoryboard" Storyboard="{StaticResource SubMenuOnMouseOut}"/>
  53. </Trigger.ExitActions>
  54. <Trigger.EnterActions>
  55. <BeginStoryboard Storyboard="{StaticResource SubMenuOnMouseOver}"/>
  56. </Trigger.EnterActions>
  57. </Trigger>
  58. <Trigger Property="IsEnabled" Value="false">
  59. <Setter Property="Foreground" Value="#FF9A9A9A"/>
  60. </Trigger>
  61. </ControlTemplate.Triggers>
  62. </ControlTemplate>
  63. <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry>
  64. <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter"/>
  65. <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry>
  66. <Style x:Key="MenuScrollButton" BasedOn="{x:Null}" TargetType="{x:Type RepeatButton}">
  67. <Setter Property="ClickMode" Value="Hover"/>
  68. <Setter Property="MinWidth" Value="0"/>
  69. <Setter Property="MinHeight" Value="0"/>
  70. <Setter Property="Template">
  71. <Setter.Value>
  72. <ControlTemplate TargetType="{x:Type RepeatButton}">
  73. <DockPanel SnapsToDevicePixels="true" Background="Transparent">
  74. <Rectangle x:Name="R1" Fill="Transparent" Width="1" DockPanel.Dock="Right"/>
  75. <Rectangle x:Name="B1" Fill="Transparent" Height="1" DockPanel.Dock="Bottom"/>
  76. <Rectangle x:Name="L1" Fill="Transparent" Width="1" DockPanel.Dock="Left"/>
  77. <Rectangle x:Name="T1" Fill="Transparent" Height="1" DockPanel.Dock="Top"/>
  78. <ContentPresenter x:Name="ContentContainer" HorizontalAlignment="Center" Margin="2,2,2,2" VerticalAlignment="Center"/>
  79. </DockPanel>
  80. <ControlTemplate.Triggers>
  81. <Trigger Property="IsPressed" Value="true">
  82. <Setter Property="Fill" TargetName="R1" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}"/>
  83. <Setter Property="Fill" TargetName="B1" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}"/>
  84. <Setter Property="Fill" TargetName="L1" Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"/>
  85. <Setter Property="Fill" TargetName="T1" Value="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"/>
  86. <Setter Property="Margin" TargetName="ContentContainer" Value="3,3,1,1"/>
  87. </Trigger>
  88. </ControlTemplate.Triggers>
  89. </ControlTemplate>
  90. </Setter.Value>
  91. </Setter>
  92. </Style>
  93. <Style x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}" BasedOn="{x:Null}" TargetType="{x:Type ScrollViewer}">
  94. <Setter Property="HorizontalScrollBarVisibility" Value="Hidden"/>
  95. <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>
  96. <Setter Property="Template">
  97. <Setter.Value>
  98. <ControlTemplate TargetType="{x:Type ScrollViewer}">
  99. <Grid SnapsToDevicePixels="true">
  100. <Grid.ColumnDefinitions>
  101. <ColumnDefinition Width="*"/>
  102. </Grid.ColumnDefinitions>
  103. <Grid.RowDefinitions>
  104. <RowDefinition Height="Auto"/>
  105. <RowDefinition Height="*"/>
  106. <RowDefinition Height="Auto"/>
  107. </Grid.RowDefinitions>
  108. <Border Grid.Column="0" Grid.Row="1">
  109. <ScrollContentPresenter Margin="{TemplateBinding Padding}"/>
  110. </Border>
  111. <RepeatButton Style="{StaticResource MenuScrollButton}" Focusable="false" Command="{x:Static ScrollBar.LineUpCommand}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="0">
  112. <RepeatButton.Visibility>
  113. <MultiBinding FallbackValue="Visibility.Collapsed" Converter="{StaticResource MenuScrollingVisibilityConverter}" ConverterParameter="0">
  114. <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/>
  115. <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/>
  116. <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
  117. <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
  118. </MultiBinding>
  119. </RepeatButton.Visibility>
  120. <Path Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" Data="{StaticResource UpArrow}"/>
  121. </RepeatButton>
  122. <RepeatButton Style="{StaticResource MenuScrollButton}" Focusable="false" Command="{x:Static ScrollBar.LineDownCommand}" CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="0" Grid.Row="2">
  123. <RepeatButton.Visibility>
  124. <MultiBinding FallbackValue="Visibility.Collapsed" Converter="{StaticResource MenuScrollingVisibilityConverter}" ConverterParameter="100">
  125. <Binding Path="ComputedVerticalScrollBarVisibility" RelativeSource="{RelativeSource TemplatedParent}"/>
  126. <Binding Path="VerticalOffset" RelativeSource="{RelativeSource TemplatedParent}"/>
  127. <Binding Path="ExtentHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
  128. <Binding Path="ViewportHeight" RelativeSource="{RelativeSource TemplatedParent}"/>
  129. </MultiBinding>
  130. </RepeatButton.Visibility>
  131. <Path Fill="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" Data="{StaticResource DownArrow}"/>
  132. </RepeatButton>
  133. </Grid>
  134. </ControlTemplate>
  135. </Setter.Value>
  136. </Setter>
  137. </Style>
  138. <ControlTemplate x:Key="{ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}" TargetType="{x:Type ContentControl}">
  139. <Border SnapsToDevicePixels="True" Background="{DynamicResource Color_BG_SubMenuBG}" MinWidth="{TemplateBinding ActualWidth}" BorderThickness="1" BorderBrush="{DynamicResource Color_BD_SubMenu}" Padding="5,0">
  140. <ContentPresenter Margin="0,5" HorizontalAlignment="Left"/>
  141. </Border>
  142. </ControlTemplate>
  143. <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}" TargetType="{x:Type MenuItem}">
  144. <ControlTemplate.Resources>
  145. <Storyboard x:Key="OnMouseOver">
  146. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Highlight">
  147. <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
  148. <SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="1" KeySpline="0,0,1,0"/>
  149. </DoubleAnimationUsingKeyFrames>
  150. </Storyboard>
  151. <Storyboard x:Key="OnMouseOut">
  152. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Highlight">
  153. <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
  154. <SplineDoubleKeyFrame KeyTime="0:0:0.2" Value="0" KeySpline="0,0,0,1"/>
  155. </DoubleAnimationUsingKeyFrames>
  156. </Storyboard>
  157. </ControlTemplate.Resources>
  158. <Grid SnapsToDevicePixels="true">
  159. <Border x:Name="BG" BorderBrush="{DynamicResource Color_BD_Menu}" BorderThickness="1" Cursor="Hand" Background="{DynamicResource Color_BG_Menu}">
  160. <Border.Effect>
  161. <DropShadowEffect Color="#FFC6E9FF" ShadowDepth="0" BlurRadius="10"/>
  162. </Border.Effect>
  163. <Grid>
  164. <Border x:Name="Highlight" Background="{DynamicResource Color_BG_Menu_Highlight}" Opacity="0">
  165. <Border.Effect>
  166. <BlurEffect/>
  167. </Border.Effect>
  168. </Border>
  169. </Grid>
  170. </Border>
  171. <ContentPresenter x:Name="contentPresenter" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" RecognizesAccessKey="True" HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="Hand">
  172. </ContentPresenter>
  173. <Popup x:Name="PART_Popup" AllowsTransparency="true" HorizontalOffset="1" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" VerticalOffset="2" Focusable="false" MinWidth="150" Grid.Column="1">
  174. <ContentControl x:Name="SubMenuBorder" IsTabStop="false" Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
  175. <ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" CanContentScroll="true">
  176. <ItemsPresenter Margin="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.IsSharedSizeScope="true" KeyboardNavigation.DirectionalNavigation="Cycle" KeyboardNavigation.TabNavigation="Cycle" Cursor="Hand"/>
  177. </ScrollViewer>
  178. </ContentControl>
  179. </Popup>
  180. </Grid>
  181. <ControlTemplate.Triggers>
  182. <Trigger Property="IsSuspendingPopupAnimation" Value="true">
  183. <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
  184. </Trigger>
  185. <Trigger Property="Icon" Value="{x:Null}"/>
  186. <Trigger Property="IsChecked" Value="true"/>
  187. <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true"/>
  188. <Trigger Property="IsHighlighted" Value="true">
  189. <Trigger.ExitActions>
  190. <BeginStoryboard x:Name="OnMouseOut_BeginStoryboard1" Storyboard="{StaticResource OnMouseOut}"/>
  191. </Trigger.ExitActions>
  192. <Trigger.EnterActions>
  193. <BeginStoryboard x:Name="OnMouseOver_BeginStoryboard" Storyboard="{StaticResource OnMouseOver}"/>
  194. </Trigger.EnterActions>
  195. </Trigger>
  196. <DataTrigger Binding="{Binding Selected}" Value="True">
  197. <Setter Property="Opacity" TargetName="Highlight" Value="1"/>
  198. </DataTrigger>
  199. <Trigger Property="IsKeyboardFocused" Value="true"/>
  200. <Trigger Property="IsSubmenuOpen" Value="true"/>
  201. <Trigger Property="IsEnabled" Value="false">
  202. <Setter Property="Foreground" Value="#FF9A9A9A"/>
  203. </Trigger>
  204. </ControlTemplate.Triggers>
  205. </ControlTemplate>
  206. <SolidColorBrush x:Key="Menu_Main_BG_Outer" Color="#FF164EA1"/>
  207. <SolidColorBrush x:Key="Menu_Main_BD_Highlight" Color="#FFC6D9FF"/>
  208. <SolidColorBrush x:Key="Menu_Main_BD_Shadow" Color="#FF111A2B"/>
  209. <LinearGradientBrush x:Key="Menu_Main_BG_Inner" EndPoint="0.5,1" StartPoint="0.5,0">
  210. <GradientStop Color="#FF5B89CC" Offset="0"/>
  211. <GradientStop Color="#FF5B89CC" Offset="1"/>
  212. <GradientStop Color="#FF5B89CC" Offset="0.4"/>
  213. <GradientStop Color="#FF5B89CC" Offset="0.401"/>
  214. <GradientStop Color="#FF5B89CC" Offset="0.9"/>
  215. </LinearGradientBrush>
  216. <SolidColorBrush x:Key="Menu_Main_BG_Outer_Highlight" Color="#FF49BD9A"/>
  217. <LinearGradientBrush x:Key="Menu_Main_BG_Inner_Highlight" EndPoint="0.5,1" StartPoint="0.5,0">
  218. <GradientStop Color="#FF49BD9A" Offset="0"/>
  219. <GradientStop Color="#FF49BD9A" Offset="1"/>
  220. <GradientStop Color="#FF49BD9A" Offset="0.4"/>
  221. <GradientStop Color="#FF49BD9A" Offset="0.401"/>
  222. <GradientStop Color="#FF49BD9A" Offset="0.9"/>
  223. </LinearGradientBrush>
  224. <ControlTemplate x:Key="SubMunu_ShowOnTop" TargetType="{x:Type MenuItem}">
  225. <Grid SnapsToDevicePixels="true">
  226. <Border x:Name="BG" BorderBrush="{DynamicResource Menu_Main_BD_Highlight}" BorderThickness="3,3,0,0" CornerRadius="8" Cursor="Hand" Background="{DynamicResource Menu_Main_BG_Outer}">
  227. <Border x:Name="InnerBD" BorderBrush="{DynamicResource Menu_Main_BD_Shadow}" BorderThickness="0,0,3,3" CornerRadius="7">
  228. <Grid Width="Auto">
  229. <Rectangle x:Name="InnerBG" Margin="2" RadiusX="6" RadiusY="6" Fill="{DynamicResource Menu_Main_BG_Inner}">
  230. <Rectangle.Effect>
  231. <BlurEffect Radius="5"/>
  232. </Rectangle.Effect>
  233. </Rectangle>
  234. <Grid x:Name="Content_Grid" SnapsToDevicePixels="true">
  235. <Grid.Effect>
  236. <DropShadowEffect ShadowDepth="0" BlurRadius="8" Color="White"/>
  237. </Grid.Effect>
  238. <ContentPresenter x:Name="contentPresenter" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" RecognizesAccessKey="True" HorizontalAlignment="Center" VerticalAlignment="Center" Cursor="Hand">
  239. <ContentPresenter.Effect>
  240. <DropShadowEffect BlurRadius="8" ShadowDepth="0" Color="White"/>
  241. </ContentPresenter.Effect>
  242. </ContentPresenter>
  243. </Grid>
  244. </Grid>
  245. </Border>
  246. </Border>
  247. <Popup x:Name="PART_Popup" AllowsTransparency="true" HorizontalOffset="0" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Top" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" VerticalOffset="-1" Focusable="false" MinWidth="150" Grid.Column="1">
  248. <ContentControl x:Name="SubMenuBorder" IsTabStop="false" Template="{DynamicResource {ComponentResourceKey ResourceId=SubmenuContent, TypeInTargetAssembly={x:Type FrameworkElement}}}">
  249. <ScrollViewer Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}" CanContentScroll="true">
  250. <ItemsPresenter Margin="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.IsSharedSizeScope="true" KeyboardNavigation.DirectionalNavigation="Cycle" KeyboardNavigation.TabNavigation="Cycle" Cursor="Hand"/>
  251. </ScrollViewer>
  252. </ContentControl>
  253. </Popup>
  254. </Grid>
  255. <ControlTemplate.Triggers>
  256. <Trigger Property="IsSuspendingPopupAnimation" Value="true">
  257. <Setter Property="PopupAnimation" TargetName="PART_Popup" Value="None"/>
  258. </Trigger>
  259. <Trigger Property="Icon" Value="{x:Null}"/>
  260. <Trigger Property="IsChecked" Value="true"/>
  261. <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true"/>
  262. <Trigger Property="IsHighlighted" Value="true">
  263. <Setter Property="Foreground" Value="{DynamicResource FG_Black}"/>
  264. <Setter Property="Effect" TargetName="Content_Grid">
  265. <Setter.Value>
  266. <DropShadowEffect BlurRadius="8" Color="White" ShadowDepth="0" Opacity="0.5"/>
  267. </Setter.Value>
  268. </Setter>
  269. <Setter Property="Effect" TargetName="contentPresenter">
  270. <Setter.Value>
  271. <DropShadowEffect BlurRadius="8" Color="White" ShadowDepth="0"/>
  272. </Setter.Value>
  273. </Setter>
  274. <Setter Property="Fill" TargetName="InnerBG" Value="{DynamicResource Menu_Main_BG_Inner_Highlight}"/>
  275. <Setter Property="Background" TargetName="BG" Value="{DynamicResource Menu_Main_BG_Outer_Highlight}"/>
  276. </Trigger>
  277. <DataTrigger Binding="{Binding Selected}" Value="True">
  278. <Setter Property="Foreground" Value="{DynamicResource FG_White}"/>
  279. <Setter Property="Effect" TargetName="Content_Grid">
  280. <Setter.Value>
  281. <DropShadowEffect BlurRadius="10" Color="Black" ShadowDepth="0" Opacity="0.5"/>
  282. </Setter.Value>
  283. </Setter>
  284. <Setter Property="Effect" TargetName="contentPresenter">
  285. <Setter.Value>
  286. <DropShadowEffect BlurRadius="10" Color="Black" ShadowDepth="0"/>
  287. </Setter.Value>
  288. </Setter>
  289. <Setter Property="Fill" TargetName="InnerBG" Value="{DynamicResource Menu_Main_BG_Inner_Highlight}"/>
  290. <Setter Property="Background" TargetName="BG" Value="{DynamicResource Menu_Main_BG_Outer_Highlight}"/>
  291. </DataTrigger>
  292. <Trigger Property="IsKeyboardFocused" Value="true"/>
  293. <Trigger Property="IsSubmenuOpen" Value="true"/>
  294. <Trigger Property="IsEnabled" Value="false">
  295. <Setter Property="Foreground" Value="#FF9A9A9A"/>
  296. </Trigger>
  297. </ControlTemplate.Triggers>
  298. </ControlTemplate>
  299. </ResourceDictionary>