WPF 为ContextMenu利用Fluent风格的亚克力材质殊效

[复制链接]
发表于 2025-11-19 17:31:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
书接上回,我们的Fluent WPF的版图已经完成了:
先来看看效果图(win11):
有以下xaml代码:
  1. <TextBlock.ContextMenu>
  2.   
  3.   <ContextMenu>
  4.   
  5.   
  6.   
  7.   <MenuItem Header="Menu Item 1" Icon="Cd" InputGestureText="aa?" />
  8.   
  9.   
  10.   
  11.   <MenuItem Header="Menu Item 2" >
  12.   
  13.   
  14.   
  15.   
  16.   
  17.   <MenuItem Header="Child Item 1" Icon="Ab" />
  18.   
  19.   
  20.   
  21.   
  22.   
  23.   <MenuItem Header="Child Item 2" Icon="Ad" />
  24.   
  25.   
  26.   
  27.   
  28.   
  29.   <MenuItem Header="Child Item 3" IsCheckable="True" IsChecked="True"/>
  30.   
  31.   
  32.   
  33.   </MenuItem>
  34.   
  35.   
  36.   
  37.   <MenuItem Header="Menu Item 3" Icon="cd" />
  38.   
  39.   </ContextMenu>
  40. </TextBlock.ContextMenu>
复制代码

(由于我的win10捏造机坏了,临时没有测试)
前面的工作已经办理了让恣意窗口支持Acrylic材质的题目,本文重点先容ContentMenu和MenuItem的样式适配和实现。
本文的Demo:
TwilightLemon/WindowEffectTest: 测试win10/11的含糊效果 (github.com)
一、为什么必要一个新的ContextMenu和MenuItem模板

如果你直接给ContextMenu应用WindowMaterial殊效,大概会出现以下貌寝的效果:

大概:

缘故因由在于古老的ContextMenu和MenuItem模板和样式并不能通过简朴修改Background实现我们想要的结构和交互效果。
二、ContextMenu与MenuItem的结构

1. ContextMenu 的结构

ContextMenu直观上看是一个Popup,但它的控件模板并不包罗Popup,而是直接指定内部元素(包罗一个ScrollViewer和StackPanel)。因此不能从控件模板中更换Popup为自界说的FluentPopup,必要利用其他本领让其内部Popup也支持Acrylic材质(见下文)。
2. MenuItem 的四种形态

在示例代码堆栈中展示了较为完备的Menu干系的结构:

MenuItem根据其在菜单树中的位置,通过Role属性分为四种形态。我们在Style.Triggers中分别为它们指定了差异的模板:

  • TopLevelHeader: 顶级菜单项,且包罗子菜单Popup(比方菜单栏上的”File”)。
  • TopLevelItem: 顶级菜单项,不含子菜单(比方菜单栏上的”Help”)。
  • SubmenuHeader: 子菜单项,且包罗下一级子菜单Popup。
  • SubmenuItem: 子菜单项,不含子菜单(叶子节点)。其模板重要处理惩罚图标、笔墨、快捷键的结构。
三、重写Menu干系控件模板和样式

1. ContextMenu 样式

ContextMenu的样式重要参考了.NET 9自带的Fluent样式,并作了一些调解以适配Acrylic材质。重要目的是覆盖原始模板的Icon部门白框和分割线:

由于我们的WindowMaterial已经为窗口主动附加上圆角、阴影和亚克力材质的DWM效果,以是我们只必要将ContextMenu的配景设置为透明,并移除不须要的边框和分割线即可。
别的,还添加了弹出动画(是在Popup内部做的,并非对window,效果大概不会很理想)。
2. MenuItem 样式

MenuItem的样式重要处理惩罚了图标、笔墨、快捷键的结构,并根据差异的脚色(TopLevelHeader、TopLevelItem、SubmenuHeader、SubmenuItem)应用差异的模板。

  • TopLevelHeader: 只包罗Icon和Header,以及弹出的Popup,只必要更换为自界说的FluentPopup即可。
  • TopLevelItem: 只包罗Icon和Header,无Popup。
  • SubmenuHeader: 包罗Icon、Header和Chevron图标(这里就是一个睁开的箭头图标,但是官方叫做雪佛龙..?),以及弹出的Popup,同样更换为FluentPopup。
  • SubmenuItem: 叶子节点,包罗Icon、Header和InputGestureText。 其模板重要处理惩罚图标、笔墨、快捷键的结构。
菜单项重要分为三个部门:Icon图标、Header笔墨和最右侧的提示笔墨或睁开箭头图标。只必要保持三个部门的结构对其即可。如果IsCheckable为True,则Icon部门被自界说图标占据(√, 当IsChecked为True时)。

以下是完备的资源字典,包罗了完备的表明。
  1. 1 <ResourceDictionary
  2. 2
  3.   
  4.   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  5. 3
  6.   
  7.   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  8. 4
  9.   
  10.   xmlns:local="clr-namespace:WindowEffectTest"
  11. 5
  12.   
  13.   xmlns:sys="clr-namespace:System;assembly=mscorlib">
  14. 6
  15. 7
  16.   
  17.   
  18. 8
  19.   
  20.   <Thickness x:Key="MenuBorderPadding">0,3,0,3</Thickness>
  21. 9
  22. 10
  23.   
  24.   
  25. 11
  26.   
  27.   <Thickness x:Key="MenuItemMargin">4,1</Thickness>
  28. 12
  29. 13
  30.   
  31.   
  32. 14
  33.   
  34.   <Thickness x:Key="MenuItemContentPadding">10,6</Thickness>
  35. 15
  36. 16
  37.   
  38.   
  39. 17
  40.   
  41.   <Thickness x:Key="TopLevelItemMargin">4</Thickness>
  42. 18
  43. 19
  44.   
  45.   
  46. 20
  47.   
  48.   <Thickness x:Key="TopLevelContentMargin">10</Thickness>
  49. 21
  50. 22
  51.   
  52.   
  53. 23
  54.   
  55.   <CornerRadius x:Key="MenuCornerRadius">4</CornerRadius>
  56. 24
  57. 25
  58.   
  59.   
  60. 26
  61.   
  62.   <CornerRadius x:Key="TopLevelCornerRadius">6</CornerRadius>
  63. 27
  64. 28
  65.   
  66.   
  67. 29
  68.   
  69.   <Duration x:Key="MenuAnimationDuration">0:0:0.167</Duration>
  70. 30
  71. 31
  72.   
  73.   
  74. 32
  75.   
  76.   <PathGeometry x:Key="CheckGraph">
  77. 33
  78.   
  79.   
  80.   
  81.   M392.533333 806.4L85.333333 503.466667l59.733334-59.733334 247.466666 247.466667L866.133333 213.333333l59.733334 59.733334L392.533333 806.4z
  82. 34
  83.   
  84.   </PathGeometry>
  85. 35
  86. 36
  87.   
  88.   
  89. 37
  90.   
  91.   <PathGeometry x:Key="ForwardGraph">
  92. 38
  93.   
  94.   
  95.   
  96.   M283.648 174.081l57.225-59.008 399.479 396.929-399.476 396.924-57.228-59.004 335.872-337.92z
  97. 39
  98.   
  99.   </PathGeometry>
  100. 40
  101. 41
  102.   
  103.   
  104. 42
  105.   
  106.   
  107. 49
  108. 50
  109.   
  110.   
  111. 51
  112.   
  113.   
  114. 66
  115. 67
  116.   
  117.   
  118. 68
  119.   
  120.   
  121. 125
  122. 126
  123.   
  124.   
  125. 127
  126.   
  127.   <ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
  128. 128
  129.   
  130.   
  131.   
  132.   <Border
  133. 129
  134.   
  135.   
  136.   
  137.   
  138.   
  139.   x:Name="Border"
  140. 130
  141.   
  142.   
  143.   
  144.   
  145.   
  146.   Margin="{StaticResource TopLevelItemMargin}"
  147. 131
  148.   
  149.   
  150.   
  151.   
  152.   
  153.   Background="{TemplateBinding Background}"
  154. 132
  155.   
  156.   
  157.   
  158.   
  159.   
  160.   BorderBrush="{TemplateBinding BorderBrush}"
  161. 133
  162.   
  163.   
  164.   
  165.   
  166.   
  167.   BorderThickness="{TemplateBinding BorderThickness}"
  168. 134
  169.   
  170.   
  171.   
  172.   
  173.   
  174.   CornerRadius="{StaticResource TopLevelCornerRadius}">
  175. 135
  176.   
  177.   
  178.   
  179.   
  180.   
  181.   <Grid>
  182. 136
  183.   
  184.   
  185.   
  186.   
  187.   
  188.   
  189.   
  190.   <Grid.RowDefinitions>
  191. 137
  192.   
  193.   
  194.   
  195.   
  196.   
  197.   
  198.   
  199.   
  200.   
  201.   <RowDefinition Height="*" />
  202. 138
  203.   
  204.   
  205.   
  206.   
  207.   
  208.   
  209.   
  210.   
  211.   
  212.   <RowDefinition Height="Auto" />
  213. 139
  214.   
  215.   
  216.   
  217.   
  218.   
  219.   
  220.   
  221.   </Grid.RowDefinitions>
  222. 140
  223. 141
  224.   
  225.   
  226.   
  227.   
  228.   
  229.   
  230.   
  231.   
  232. 142
  233.   
  234.   
  235.   
  236.   
  237.   
  238.   
  239.   
  240.   <Grid Margin="{StaticResource TopLevelContentMargin}">
  241. 143
  242.   
  243.   
  244.   
  245.   
  246.   
  247.   
  248.   
  249.   
  250.   
  251.   <Grid.ColumnDefinitions>
  252. 144
  253.   
  254.   
  255.   
  256.   
  257.   
  258.   
  259.   
  260.   
  261.   
  262.   
  263.   
  264.   <ColumnDefinition Width="Auto" />
  265. 145
  266.   
  267.   
  268.   
  269.   
  270.   
  271.   
  272.   
  273.   
  274.   
  275.   
  276.   
  277.   <ColumnDefinition Width="*" />
  278. 146
  279.   
  280.   
  281.   
  282.   
  283.   
  284.   
  285.   
  286.   
  287.   
  288.   </Grid.ColumnDefinitions>
  289. 147
  290. 148
  291.   
  292.   
  293.   
  294.   
  295.   
  296.   
  297.   
  298.   
  299.   
  300.   
  301. 149
  302.   
  303.   
  304.   
  305.   
  306.   
  307.   
  308.   
  309.   
  310.   
  311.   <ContentPresenter
  312. 150
  313.   
  314.   
  315.   
  316.   
  317.   
  318.   
  319.   
  320.   
  321.   
  322.   
  323.   
  324.   x:Name="Icon"
  325. 151
  326.   
  327.   
  328.   
  329.   
  330.   
  331.   
  332.   
  333.   
  334.   
  335.   
  336.   
  337.   Grid.Column="0"
  338. 152
  339.   
  340.   
  341.   
  342.   
  343.   
  344.   
  345.   
  346.   
  347.   
  348.   
  349.   
  350.   Margin="0,0,6,0"
  351. 153
  352.   
  353.   
  354.   
  355.   
  356.   
  357.   
  358.   
  359.   
  360.   
  361.   
  362.   
  363.   VerticalAlignment="Center"
  364. 154
  365.   
  366.   
  367.   
  368.   
  369.   
  370.   
  371.   
  372.   
  373.   
  374.   
  375.   
  376.   Content="{TemplateBinding Icon}"
  377. 155
  378.   
  379.   
  380.   
  381.   
  382.   
  383.   
  384.   
  385.   
  386.   
  387.   
  388.   
  389.   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  390. 156
  391. 157
  392.   
  393.   
  394.   
  395.   
  396.   
  397.   
  398.   
  399.   
  400.   
  401.   
  402. 158
  403.   
  404.   
  405.   
  406.   
  407.   
  408.   
  409.   
  410.   
  411.   
  412.   <ContentPresenter
  413. 159
  414.   
  415.   
  416.   
  417.   
  418.   
  419.   
  420.   
  421.   
  422.   
  423.   
  424.   
  425.   x:Name="HeaderPresenter"
  426. 160
  427.   
  428.   
  429.   
  430.   
  431.   
  432.   
  433.   
  434.   
  435.   
  436.   
  437.   
  438.   Grid.Column="1"
  439. 161
  440.   
  441.   
  442.   
  443.   
  444.   
  445.   
  446.   
  447.   
  448.   
  449.   
  450.   
  451.   Margin="{TemplateBinding Padding}"
  452. 162
  453.   
  454.   
  455.   
  456.   
  457.   
  458.   
  459.   
  460.   
  461.   
  462.   
  463.   
  464.   VerticalAlignment="Center"
  465. 163
  466.   
  467.   
  468.   
  469.   
  470.   
  471.   
  472.   
  473.   
  474.   
  475.   
  476.   
  477.   ContentSource="Header"
  478. 164
  479.   
  480.   
  481.   
  482.   
  483.   
  484.   
  485.   
  486.   
  487.   
  488.   
  489.   
  490.   RecognizesAccessKey="True"
  491. 165
  492.   
  493.   
  494.   
  495.   
  496.   
  497.   
  498.   
  499.   
  500.   
  501.   
  502.   
  503.   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  504. 166
  505.   
  506.   
  507.   
  508.   
  509.   
  510.   
  511.   
  512.   
  513.   
  514.   
  515.   
  516.   TextElement.Foreground="{TemplateBinding Foreground}" />
  517. 167
  518.   
  519.   
  520.   
  521.   
  522.   
  523.   
  524.   
  525.   </Grid>
  526. 168
  527. 169
  528.   
  529.   
  530.   
  531.   
  532.   
  533.   
  534.   
  535.   
  536. 170
  537.   
  538.   
  539.   
  540.   
  541.   
  542.   
  543.   
  544.   <local:FluentPopup
  545. 171
  546.   
  547.   
  548.   
  549.   
  550.   
  551.   
  552.   
  553.   
  554.   
  555.   x:Name="PART_Popup"
  556. 172
  557.   
  558.   
  559.   
  560.   
  561.   
  562.   
  563.   
  564.   
  565.   
  566.   Grid.Row="1"
  567. 173
  568.   
  569.   
  570.   
  571.   
  572.   
  573.   
  574.   
  575.   
  576.   
  577.   Grid.Column="0"
  578. 174
  579.   
  580.   
  581.   
  582.   
  583.   
  584.   
  585.   
  586.   
  587.   
  588.   Focusable="False"
  589. 175
  590.   
  591.   
  592.   
  593.   
  594.   
  595.   
  596.   
  597.   
  598.   
  599.   HorizontalOffset="-12"
  600. 176
  601.   
  602.   
  603.   
  604.   
  605.   
  606.   
  607.   
  608.   
  609.   
  610.   IsOpen="{TemplateBinding IsSubmenuOpen}"
  611. 177
  612.   
  613.   
  614.   
  615.   
  616.   
  617.   
  618.   
  619.   
  620.   
  621.   Placement="Bottom"
  622. 178
  623.   
  624.   
  625.   
  626.   
  627.   
  628.   
  629.   
  630.   
  631.   
  632.   PlacementTarget="{Binding ElementName=Border}"
  633. 179
  634.   
  635.   
  636.   
  637.   
  638.   
  639.   
  640.   
  641.   
  642.   
  643.   PopupAnimation="None"
  644. 180
  645.   
  646.   
  647.   
  648.   
  649.   
  650.   
  651.   
  652.   
  653.   
  654.   VerticalOffset="1">
  655. 181
  656.   
  657.   
  658.   
  659.   
  660.   
  661.   
  662.   
  663.   
  664.   
  665.   <Grid
  666. 182
  667.   
  668.   
  669.   
  670.   
  671.   
  672.   
  673.   
  674.   
  675.   
  676.   
  677.   
  678.   x:Name="SubmenuBorder"
  679. 183
  680.   
  681.   
  682.   
  683.   
  684.   
  685.   
  686.   
  687.   
  688.   
  689.   
  690.   
  691.   Background="{DynamicResource PopupWindowBackground}"
  692. 184
  693.   
  694.   
  695.   
  696.   
  697.   
  698.   
  699.   
  700.   
  701.   
  702.   
  703.   
  704.   SnapsToDevicePixels="True">
  705. 185
  706.   
  707.   
  708.   
  709.   
  710.   
  711.   
  712.   
  713.   
  714.   
  715.   
  716.   
  717.   
  718. 186
  719.   
  720.   
  721.   
  722.   
  723.   
  724.   
  725.   
  726.   
  727.   
  728.   
  729.   
  730.   <Grid.RenderTransform>
  731. 187
  732.   
  733.   
  734.   
  735.   
  736.   
  737.   
  738.   
  739.   
  740.   
  741.   
  742.   
  743.   
  744.   
  745.   <TranslateTransform />
  746. 188
  747.   
  748.   
  749.   
  750.   
  751.   
  752.   
  753.   
  754.   
  755.   
  756.   
  757.   
  758.   </Grid.RenderTransform>
  759. 189
  760.   
  761.   
  762.   
  763.   
  764.   
  765.   
  766.   
  767.   
  768.   
  769.   
  770.   
  771.   <ScrollViewer
  772. 190
  773.   
  774.   
  775.   
  776.   
  777.   
  778.   
  779.   
  780.   
  781.   
  782.   
  783.   
  784.   
  785.   
  786.   Padding="{StaticResource MenuBorderPadding}"
  787. 191
  788.   
  789.   
  790.   
  791.   
  792.   
  793.   
  794.   
  795.   
  796.   
  797.   
  798.   
  799.   
  800.   
  801.   CanContentScroll="True"
  802. 192
  803.   
  804.   
  805.   
  806.   
  807.   
  808.   
  809.   
  810.   
  811.   
  812.   
  813.   
  814.   
  815.   
  816.   Style="{StaticResource MenuItemScrollViewerStyle}">
  817. 193
  818.   
  819.   
  820.   
  821.   
  822.   
  823.   
  824.   
  825.   
  826.   
  827.   
  828.   
  829.   
  830.   
  831.   <Grid>
  832. 194
  833.   
  834.   
  835.   
  836.   
  837.   
  838.   
  839.   
  840.   
  841.   
  842.   
  843.   
  844.   
  845.   
  846.   
  847.   
  848.   
  849. 195
  850.   
  851.   
  852.   
  853.   
  854.   
  855.   
  856.   
  857.   
  858.   
  859.   
  860.   
  861.   
  862.   
  863.   
  864.   
  865.   <ItemsPresenter
  866. 196
  867.   
  868.   
  869.   
  870.   
  871.   
  872.   
  873.   
  874.   
  875.   
  876.   
  877.   
  878.   
  879.   
  880.   
  881.   
  882.   
  883.   
  884.   x:Name="ItemsPresenter"
  885. 197
  886.   
  887.   
  888.   
  889.   
  890.   
  891.   
  892.   
  893.   
  894.   
  895.   
  896.   
  897.   
  898.   
  899.   
  900.   
  901.   
  902.   
  903.   Grid.IsSharedSizeScope="True"
  904. 198
  905.   
  906.   
  907.   
  908.   
  909.   
  910.   
  911.   
  912.   
  913.   
  914.   
  915.   
  916.   
  917.   
  918.   
  919.   
  920.   
  921.   
  922.   KeyboardNavigation.DirectionalNavigation="Cycle"
  923. 199
  924.   
  925.   
  926.   
  927.   
  928.   
  929.   
  930.   
  931.   
  932.   
  933.   
  934.   
  935.   
  936.   
  937.   
  938.   
  939.   
  940.   
  941.   KeyboardNavigation.TabNavigation="Cycle"
  942. 200
  943.   
  944.   
  945.   
  946.   
  947.   
  948.   
  949.   
  950.   
  951.   
  952.   
  953.   
  954.   
  955.   
  956.   
  957.   
  958.   
  959.   
  960.   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  961. 201
  962.   
  963.   
  964.   
  965.   
  966.   
  967.   
  968.   
  969.   
  970.   
  971.   
  972.   
  973.   
  974.   
  975.   </Grid>
  976. 202
  977.   
  978.   
  979.   
  980.   
  981.   
  982.   
  983.   
  984.   
  985.   
  986.   
  987.   
  988.   </ScrollViewer>
  989. 203
  990.   
  991.   
  992.   
  993.   
  994.   
  995.   
  996.   
  997.   
  998.   
  999.   </Grid>
  1000. 204
  1001.   
  1002.   
  1003.   
  1004.   
  1005.   
  1006.   
  1007.   
  1008.   </local:FluentPopup>
  1009. 205
  1010.   
  1011.   
  1012.   
  1013.   
  1014.   
  1015.   </Grid>
  1016. 206
  1017.   
  1018.   
  1019.   
  1020.   </Border>
  1021. 207
  1022.   
  1023.   
  1024.   
  1025.   <ControlTemplate.Triggers>
  1026. 208
  1027.   
  1028.   
  1029.   
  1030.   
  1031.   
  1032.   
  1033. 209
  1034.   
  1035.   
  1036.   
  1037.   
  1038.   
  1039.   <Trigger Property="Icon" Value="{x:Null}">
  1040. 210
  1041.   
  1042.   
  1043.   
  1044.   
  1045.   
  1046.   
  1047.   
  1048.   <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
  1049. 211
  1050.   
  1051.   
  1052.   
  1053.   
  1054.   
  1055.   </Trigger>
  1056. 212
  1057.   
  1058.   
  1059.   
  1060.   
  1061.   
  1062.   
  1063. 213
  1064.   
  1065.   
  1066.   
  1067.   
  1068.   
  1069.   <Trigger Property="Header" Value="{x:Null}">
  1070. 214
  1071.   
  1072.   
  1073.   
  1074.   
  1075.   
  1076.   
  1077.   
  1078.   <Setter TargetName="Icon" Property="Margin" Value="0" />
  1079. 215
  1080.   
  1081.   
  1082.   
  1083.   
  1084.   
  1085.   
  1086.   
  1087.   <Setter TargetName="HeaderPresenter" Property="Visibility" Value="Collapsed" />
  1088. 216
  1089.   
  1090.   
  1091.   
  1092.   
  1093.   
  1094.   </Trigger>
  1095. 217
  1096.   
  1097.   
  1098.   
  1099.   
  1100.   
  1101.   
  1102. 218
  1103.   
  1104.   
  1105.   
  1106.   
  1107.   
  1108.   <Trigger Property="IsHighlighted" Value="True">
  1109. 219
  1110.   
  1111.   
  1112.   
  1113.   
  1114.   
  1115.   
  1116.   
  1117.   <Setter TargetName="Border" Property="Background" Value="{DynamicResource MaskColor}" />
  1118. 220
  1119.   
  1120.   
  1121.   
  1122.   
  1123.   
  1124.   </Trigger>
  1125. 221
  1126.   
  1127.   
  1128.   
  1129.   
  1130.   
  1131.   
  1132. 222
  1133.   
  1134.   
  1135.   
  1136.   
  1137.   
  1138.   <Trigger Property="IsSubmenuOpen" Value="True">
  1139. 223
  1140.   
  1141.   
  1142.   
  1143.   
  1144.   
  1145.   
  1146.   
  1147.   <Trigger.EnterActions>
  1148. 224
  1149.   
  1150.   
  1151.   
  1152.   
  1153.   
  1154.   
  1155.   
  1156.   
  1157.   
  1158.   <BeginStoryboard>
  1159. 225
  1160.   
  1161.   
  1162.   
  1163.   
  1164.   
  1165.   
  1166.   
  1167.   
  1168.   
  1169.   
  1170.   
  1171.   <Storyboard>
  1172. 226
  1173.   
  1174.   
  1175.   
  1176.   
  1177.   
  1178.   
  1179.   
  1180.   
  1181.   
  1182.   
  1183.   
  1184.   
  1185.   
  1186.   <DoubleAnimation
  1187. 227
  1188.   
  1189.   
  1190.   
  1191.   
  1192.   
  1193.   
  1194.   
  1195.   
  1196.   
  1197.   
  1198.   
  1199.   
  1200.   
  1201.   
  1202.   
  1203.   Storyboard.TargetName="SubmenuBorder"
  1204. 228
  1205.   
  1206.   
  1207.   
  1208.   
  1209.   
  1210.   
  1211.   
  1212.   
  1213.   
  1214.   
  1215.   
  1216.   
  1217.   
  1218.   
  1219.   
  1220.   Storyboard.TargetProperty="(Border.RenderTransform).(TranslateTransform.Y)"
  1221. 229
  1222.   
  1223.   
  1224.   
  1225.   
  1226.   
  1227.   
  1228.   
  1229.   
  1230.   
  1231.   
  1232.   
  1233.   
  1234.   
  1235.   
  1236.   
  1237.   From="-45"
  1238. 230
  1239.   
  1240.   
  1241.   
  1242.   
  1243.   
  1244.   
  1245.   
  1246.   
  1247.   
  1248.   
  1249.   
  1250.   
  1251.   
  1252.   
  1253.   
  1254.   To="0"
  1255. 231
  1256.   
  1257.   
  1258.   
  1259.   
  1260.   
  1261.   
  1262.   
  1263.   
  1264.   
  1265.   
  1266.   
  1267.   
  1268.   
  1269.   
  1270.   
  1271.   Duration="{StaticResource MenuAnimationDuration}">
  1272. 232
  1273.   
  1274.   
  1275.   
  1276.   
  1277.   
  1278.   
  1279.   
  1280.   
  1281.   
  1282.   
  1283.   
  1284.   
  1285.   
  1286.   
  1287.   
  1288.   <DoubleAnimation.EasingFunction>
  1289. 233
  1290.   
  1291.   
  1292.   
  1293.   
  1294.   
  1295.   
  1296.   
  1297.   
  1298.   
  1299.   
  1300.   
  1301.   
  1302.   
  1303.   
  1304.   
  1305.   
  1306.   
  1307.   <CircleEase EasingMode="EaseOut" />
  1308. 234
  1309.   
  1310.   
  1311.   
  1312.   
  1313.   
  1314.   
  1315.   
  1316.   
  1317.   
  1318.   
  1319.   
  1320.   
  1321.   
  1322.   
  1323.   
  1324.   </DoubleAnimation.EasingFunction>
  1325. 235
  1326.   
  1327.   
  1328.   
  1329.   
  1330.   
  1331.   
  1332.   
  1333.   
  1334.   
  1335.   
  1336.   
  1337.   
  1338.   
  1339.   </DoubleAnimation>
  1340. 236
  1341.   
  1342.   
  1343.   
  1344.   
  1345.   
  1346.   
  1347.   
  1348.   
  1349.   
  1350.   
  1351.   
  1352.   </Storyboard>
  1353. 237
  1354.   
  1355.   
  1356.   
  1357.   
  1358.   
  1359.   
  1360.   
  1361.   
  1362.   
  1363.   </BeginStoryboard>
  1364. 238
  1365.   
  1366.   
  1367.   
  1368.   
  1369.   
  1370.   
  1371.   
  1372.   </Trigger.EnterActions>
  1373. 239
  1374.   
  1375.   
  1376.   
  1377.   
  1378.   
  1379.   </Trigger>
  1380. 240
  1381.   
  1382.   
  1383.   
  1384.   </ControlTemplate.Triggers>
  1385. 241
  1386.   
  1387.   </ControlTemplate>
  1388. 242
  1389. 243
  1390.   
  1391.   
  1392. 244
  1393.   
  1394.   <ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="{x:Type MenuItem}">
  1395. 245
  1396.   
  1397.   
  1398.   
  1399.   <Border
  1400. 246
  1401.   
  1402.   
  1403.   
  1404.   
  1405.   
  1406.   x:Name="Border"
  1407. 247
  1408.   
  1409.   
  1410.   
  1411.   
  1412.   
  1413.   Margin="{StaticResource TopLevelItemMargin}"
  1414. 248
  1415.   
  1416.   
  1417.   
  1418.   
  1419.   
  1420.   Background="{TemplateBinding Background}"
  1421. 249
  1422.   
  1423.   
  1424.   
  1425.   
  1426.   
  1427.   BorderBrush="{TemplateBinding BorderBrush}"
  1428. 250
  1429.   
  1430.   
  1431.   
  1432.   
  1433.   
  1434.   BorderThickness="{TemplateBinding BorderThickness}"
  1435. 251
  1436.   
  1437.   
  1438.   
  1439.   
  1440.   
  1441.   CornerRadius="{StaticResource TopLevelCornerRadius}">
  1442. 252
  1443.   
  1444.   
  1445.   
  1446.   
  1447.   
  1448.   <Grid Margin="{StaticResource TopLevelContentMargin}">
  1449. 253
  1450.   
  1451.   
  1452.   
  1453.   
  1454.   
  1455.   
  1456.   
  1457.   <Grid.ColumnDefinitions>
  1458. 254
  1459.   
  1460.   
  1461.   
  1462.   
  1463.   
  1464.   
  1465.   
  1466.   
  1467.   
  1468.   <ColumnDefinition Width="Auto" />
  1469. 255
  1470.   
  1471.   
  1472.   
  1473.   
  1474.   
  1475.   
  1476.   
  1477.   
  1478.   
  1479.   <ColumnDefinition Width="*" />
  1480. 256
  1481.   
  1482.   
  1483.   
  1484.   
  1485.   
  1486.   
  1487.   
  1488.   </Grid.ColumnDefinitions>
  1489. 257
  1490. 258
  1491.   
  1492.   
  1493.   
  1494.   
  1495.   
  1496.   
  1497.   
  1498.   
  1499. 259
  1500.   
  1501.   
  1502.   
  1503.   
  1504.   
  1505.   
  1506.   
  1507.   <ContentPresenter
  1508. 260
  1509.   
  1510.   
  1511.   
  1512.   
  1513.   
  1514.   
  1515.   
  1516.   
  1517.   
  1518.   x:Name="Icon"
  1519. 261
  1520.   
  1521.   
  1522.   
  1523.   
  1524.   
  1525.   
  1526.   
  1527.   
  1528.   
  1529.   Grid.Column="0"
  1530. 262
  1531.   
  1532.   
  1533.   
  1534.   
  1535.   
  1536.   
  1537.   
  1538.   
  1539.   
  1540.   Margin="0,0,6,0"
  1541. 263
  1542.   
  1543.   
  1544.   
  1545.   
  1546.   
  1547.   
  1548.   
  1549.   
  1550.   
  1551.   VerticalAlignment="Center"
  1552. 264
  1553.   
  1554.   
  1555.   
  1556.   
  1557.   
  1558.   
  1559.   
  1560.   
  1561.   
  1562.   Content="{TemplateBinding Icon}"
  1563. 265
  1564.   
  1565.   
  1566.   
  1567.   
  1568.   
  1569.   
  1570.   
  1571.   
  1572.   
  1573.   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  1574. 266
  1575. 267
  1576.   
  1577.   
  1578.   
  1579.   
  1580.   
  1581.   
  1582.   
  1583.   
  1584. 268
  1585.   
  1586.   
  1587.   
  1588.   
  1589.   
  1590.   
  1591.   
  1592.   <ContentPresenter
  1593. 269
  1594.   
  1595.   
  1596.   
  1597.   
  1598.   
  1599.   
  1600.   
  1601.   
  1602.   
  1603.   x:Name="HeaderPresenter"
  1604. 270
  1605.   
  1606.   
  1607.   
  1608.   
  1609.   
  1610.   
  1611.   
  1612.   
  1613.   
  1614.   Grid.Column="1"
  1615. 271
  1616.   
  1617.   
  1618.   
  1619.   
  1620.   
  1621.   
  1622.   
  1623.   
  1624.   
  1625.   Margin="{TemplateBinding Padding}"
  1626. 272
  1627.   
  1628.   
  1629.   
  1630.   
  1631.   
  1632.   
  1633.   
  1634.   
  1635.   
  1636.   VerticalAlignment="Center"
  1637. 273
  1638.   
  1639.   
  1640.   
  1641.   
  1642.   
  1643.   
  1644.   
  1645.   
  1646.   
  1647.   ContentSource="Header"
  1648. 274
  1649.   
  1650.   
  1651.   
  1652.   
  1653.   
  1654.   
  1655.   
  1656.   
  1657.   
  1658.   RecognizesAccessKey="True"
  1659. 275
  1660.   
  1661.   
  1662.   
  1663.   
  1664.   
  1665.   
  1666.   
  1667.   
  1668.   
  1669.   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  1670. 276
  1671.   
  1672.   
  1673.   
  1674.   
  1675.   
  1676.   
  1677.   
  1678.   
  1679.   
  1680.   TextElement.Foreground="{TemplateBinding Foreground}" />
  1681. 277
  1682.   
  1683.   
  1684.   
  1685.   
  1686.   
  1687.   </Grid>
  1688. 278
  1689.   
  1690.   
  1691.   
  1692.   </Border>
  1693. 279
  1694.   
  1695.   
  1696.   
  1697.   <ControlTemplate.Triggers>
  1698. 280
  1699.   
  1700.   
  1701.   
  1702.   
  1703.   
  1704.   
  1705. 281
  1706.   
  1707.   
  1708.   
  1709.   
  1710.   
  1711.   <Trigger Property="IsHighlighted" Value="True">
  1712. 282
  1713.   
  1714.   
  1715.   
  1716.   
  1717.   
  1718.   
  1719.   
  1720.   <Setter TargetName="Border" Property="Background" Value="{DynamicResource MaskColor}" />
  1721. 283
  1722.   
  1723.   
  1724.   
  1725.   
  1726.   
  1727.   </Trigger>
  1728. 284
  1729.   
  1730.   
  1731.   
  1732.   
  1733.   
  1734.   <Trigger Property="Icon" Value="{x:Null}">
  1735. 285
  1736.   
  1737.   
  1738.   
  1739.   
  1740.   
  1741.   
  1742.   
  1743.   <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
  1744. 286
  1745.   
  1746.   
  1747.   
  1748.   
  1749.   
  1750.   </Trigger>
  1751. 287
  1752.   
  1753.   
  1754.   
  1755.   
  1756.   
  1757.   <Trigger Property="Header" Value="{x:Null}">
  1758. 288
  1759.   
  1760.   
  1761.   
  1762.   
  1763.   
  1764.   
  1765.   
  1766.   <Setter TargetName="Icon" Property="Margin" Value="0" />
  1767. 289
  1768.   
  1769.   
  1770.   
  1771.   
  1772.   
  1773.   
  1774.   
  1775.   <Setter TargetName="HeaderPresenter" Property="Visibility" Value="Collapsed" />
  1776. 290
  1777.   
  1778.   
  1779.   
  1780.   
  1781.   
  1782.   </Trigger>
  1783. 291
  1784.   
  1785.   
  1786.   
  1787.   </ControlTemplate.Triggers>
  1788. 292
  1789.   
  1790.   </ControlTemplate>
  1791. 293
  1792. 294
  1793.   
  1794.   
  1795. 295
  1796.   
  1797.   <ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}" TargetType="{x:Type MenuItem}">
  1798. 296
  1799.   
  1800.   
  1801.   
  1802.   <Border
  1803. 297
  1804.   
  1805.   
  1806.   
  1807.   
  1808.   
  1809.   x:Name="Border"
  1810. 298
  1811.   
  1812.   
  1813.   
  1814.   
  1815.   
  1816.   Margin="{StaticResource MenuItemMargin}"
  1817. 299
  1818.   
  1819.   
  1820.   
  1821.   
  1822.   
  1823.   Background="{TemplateBinding Background}"
  1824. 300
  1825.   
  1826.   
  1827.   
  1828.   
  1829.   
  1830.   BorderBrush="{TemplateBinding BorderBrush}"
  1831. 301
  1832.   
  1833.   
  1834.   
  1835.   
  1836.   
  1837.   BorderThickness="{TemplateBinding BorderThickness}"
  1838. 302
  1839.   
  1840.   
  1841.   
  1842.   
  1843.   
  1844.   CornerRadius="{StaticResource MenuCornerRadius}">
  1845. 303
  1846.   
  1847.   
  1848.   
  1849.   
  1850.   
  1851.   <Grid Margin="{StaticResource MenuItemContentPadding}">
  1852. 304
  1853.   
  1854.   
  1855.   
  1856.   
  1857.   
  1858.   
  1859.   
  1860.   <Grid.ColumnDefinitions>
  1861. 305
  1862.   
  1863.   
  1864.   
  1865.   
  1866.   
  1867.   
  1868.   
  1869.   
  1870.   
  1871.   
  1872. 306
  1873.   
  1874.   
  1875.   
  1876.   
  1877.   
  1878.   
  1879.   
  1880.   
  1881.   
  1882.   <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIconCol" />
  1883. 307
  1884.   
  1885.   
  1886.   
  1887.   
  1888.   
  1889.   
  1890.   
  1891.   
  1892.   
  1893.   
  1894. 308
  1895.   
  1896.   
  1897.   
  1898.   
  1899.   
  1900.   
  1901.   
  1902.   
  1903.   
  1904.   <ColumnDefinition Width="*" />
  1905. 309
  1906.   
  1907.   
  1908.   
  1909.   
  1910.   
  1911.   
  1912.   
  1913.   
  1914.   
  1915.   
  1916. 310
  1917.   
  1918.   
  1919.   
  1920.   
  1921.   
  1922.   
  1923.   
  1924.   
  1925.   
  1926.   <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemRightPartCol" />
  1927. 311
  1928.   
  1929.   
  1930.   
  1931.   
  1932.   
  1933.   
  1934.   
  1935.   </Grid.ColumnDefinitions>
  1936. 312
  1937. 313
  1938.   
  1939.   
  1940.   
  1941.   
  1942.   
  1943.   
  1944.   
  1945.   
  1946. 314
  1947.   
  1948.   
  1949.   
  1950.   
  1951.   
  1952.   
  1953.   
  1954.   <Border
  1955. 315
  1956.   
  1957.   
  1958.   
  1959.   
  1960.   
  1961.   
  1962.   
  1963.   
  1964.   
  1965.   x:Name="CheckBoxIconBorder"
  1966. 316
  1967.   
  1968.   
  1969.   
  1970.   
  1971.   
  1972.   
  1973.   
  1974.   
  1975.   
  1976.   Grid.Column="0"
  1977. 317
  1978.   
  1979.   
  1980.   
  1981.   
  1982.   
  1983.   
  1984.   
  1985.   
  1986.   
  1987.   VerticalAlignment="Center"
  1988. 318
  1989.   
  1990.   
  1991.   
  1992.   
  1993.   
  1994.   
  1995.   
  1996.   
  1997.   
  1998.   Visibility="Collapsed">
  1999. 319
  2000.   
  2001.   
  2002.   
  2003.   
  2004.   
  2005.   
  2006.   
  2007.   
  2008.   
  2009.   <Path
  2010. 320
  2011.   
  2012.   
  2013.   
  2014.   
  2015.   
  2016.   
  2017.   
  2018.   
  2019.   
  2020.   
  2021.   
  2022.   x:Name="CheckBoxIcon"
  2023. 321
  2024.   
  2025.   
  2026.   
  2027.   
  2028.   
  2029.   
  2030.   
  2031.   
  2032.   
  2033.   
  2034.   
  2035.   Width="10"
  2036. 322
  2037.   
  2038.   
  2039.   
  2040.   
  2041.   
  2042.   
  2043.   
  2044.   
  2045.   
  2046.   
  2047.   
  2048.   Height="10"
  2049. 323
  2050.   
  2051.   
  2052.   
  2053.   
  2054.   
  2055.   
  2056.   
  2057.   
  2058.   
  2059.   
  2060.   
  2061.   HorizontalAlignment="Left"
  2062. 324
  2063.   
  2064.   
  2065.   
  2066.   
  2067.   
  2068.   
  2069.   
  2070.   
  2071.   
  2072.   
  2073.   
  2074.   VerticalAlignment="Center"
  2075. 325
  2076.   
  2077.   
  2078.   
  2079.   
  2080.   
  2081.   
  2082.   
  2083.   
  2084.   
  2085.   
  2086.   
  2087.   Fill="{TemplateBinding Foreground}"
  2088. 326
  2089.   
  2090.   
  2091.   
  2092.   
  2093.   
  2094.   
  2095.   
  2096.   
  2097.   
  2098.   
  2099.   
  2100.   Stretch="Uniform" />
  2101. 327
  2102.   
  2103.   
  2104.   
  2105.   
  2106.   
  2107.   
  2108.   
  2109.   </Border>
  2110. 328
  2111. 329
  2112.   
  2113.   
  2114.   
  2115.   
  2116.   
  2117.   
  2118.   
  2119.   
  2120. 330
  2121.   
  2122.   
  2123.   
  2124.   
  2125.   
  2126.   
  2127.   
  2128.   <ContentPresenter
  2129. 331
  2130.   
  2131.   
  2132.   
  2133.   
  2134.   
  2135.   
  2136.   
  2137.   
  2138.   
  2139.   x:Name="Icon"
  2140. 332
  2141.   
  2142.   
  2143.   
  2144.   
  2145.   
  2146.   
  2147.   
  2148.   
  2149.   
  2150.   Grid.Column="0"
  2151. 333
  2152.   
  2153.   
  2154.   
  2155.   
  2156.   
  2157.   
  2158.   
  2159.   
  2160.   
  2161.   Margin="0,0,6,0"
  2162. 334
  2163.   
  2164.   
  2165.   
  2166.   
  2167.   
  2168.   
  2169.   
  2170.   
  2171.   
  2172.   VerticalAlignment="Center"
  2173. 335
  2174.   
  2175.   
  2176.   
  2177.   
  2178.   
  2179.   
  2180.   
  2181.   
  2182.   
  2183.   Content="{TemplateBinding Icon}"
  2184. 336
  2185.   
  2186.   
  2187.   
  2188.   
  2189.   
  2190.   
  2191.   
  2192.   
  2193.   
  2194.   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  2195. 337
  2196. 338
  2197.   
  2198.   
  2199.   
  2200.   
  2201.   
  2202.   
  2203.   
  2204.   
  2205. 339
  2206.   
  2207.   
  2208.   
  2209.   
  2210.   
  2211.   
  2212.   
  2213.   <ContentPresenter
  2214. 340
  2215.   
  2216.   
  2217.   
  2218.   
  2219.   
  2220.   
  2221.   
  2222.   
  2223.   
  2224.   Grid.Column="1"
  2225. 341
  2226.   
  2227.   
  2228.   
  2229.   
  2230.   
  2231.   
  2232.   
  2233.   
  2234.   
  2235.   Margin="{TemplateBinding Padding}"
  2236. 342
  2237.   
  2238.   
  2239.   
  2240.   
  2241.   
  2242.   
  2243.   
  2244.   
  2245.   
  2246.   VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  2247. 343
  2248.   
  2249.   
  2250.   
  2251.   
  2252.   
  2253.   
  2254.   
  2255.   
  2256.   
  2257.   ContentSource="Header"
  2258. 344
  2259.   
  2260.   
  2261.   
  2262.   
  2263.   
  2264.   
  2265.   
  2266.   
  2267.   
  2268.   RecognizesAccessKey="True"
  2269. 345
  2270.   
  2271.   
  2272.   
  2273.   
  2274.   
  2275.   
  2276.   
  2277.   
  2278.   
  2279.   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
  2280. 346
  2281.   
  2282.   
  2283.   
  2284.   
  2285.   
  2286.   
  2287.   
  2288.   
  2289.   
  2290.   TextElement.Foreground="{TemplateBinding Foreground}" />
  2291. 347
  2292. 348
  2293.   
  2294.   
  2295.   
  2296.   
  2297.   
  2298.   
  2299.   
  2300.   
  2301. 349
  2302.   
  2303.   
  2304.   
  2305.   
  2306.   
  2307.   
  2308.   
  2309.   <TextBlock
  2310. 350
  2311.   
  2312.   
  2313.   
  2314.   
  2315.   
  2316.   
  2317.   
  2318.   
  2319.   
  2320.   x:Name="InputGestureText"
  2321. 351
  2322.   
  2323.   
  2324.   
  2325.   
  2326.   
  2327.   
  2328.   
  2329.   
  2330.   
  2331.   Grid.Column="2"
  2332. 352
  2333.   
  2334.   
  2335.   
  2336.   
  2337.   
  2338.   
  2339.   
  2340.   
  2341.   
  2342.   Margin="25,0,0,0"
  2343. 353
  2344.   
  2345.   
  2346.   
  2347.   
  2348.   
  2349.   
  2350.   
  2351.   
  2352.   
  2353.   VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  2354. 354
  2355.   
  2356.   
  2357.   
  2358.   
  2359.   
  2360.   
  2361.   
  2362.   
  2363.   
  2364.   DockPanel.Dock="Right"
  2365. 355
  2366.   
  2367.   
  2368.   
  2369.   
  2370.   
  2371.   
  2372.   
  2373.   
  2374.   
  2375.   FontSize="11"
  2376. 356
  2377.   
  2378.   
  2379.   
  2380.   
  2381.   
  2382.   
  2383.   
  2384.   
  2385.   
  2386.   Opacity="0.67"
  2387. 357
  2388.   
  2389.   
  2390.   
  2391.   
  2392.   
  2393.   
  2394.   
  2395.   
  2396.   
  2397.   Text="{TemplateBinding InputGestureText}" />
  2398. 358
  2399.   
  2400.   
  2401.   
  2402.   
  2403.   
  2404.   </Grid>
  2405. 359
  2406.   
  2407.   
  2408.   
  2409.   </Border>
  2410. 360
  2411.   
  2412.   
  2413.   
  2414.   <ControlTemplate.Triggers>
  2415. 361
  2416.   
  2417.   
  2418.   
  2419.   
  2420.   
  2421.   
  2422. 362
  2423.   
  2424.   
  2425.   
  2426.   
  2427.   
  2428.   <Trigger Property="IsHighlighted" Value="True">
  2429. 363
  2430.   
  2431.   
  2432.   
  2433.   
  2434.   
  2435.   
  2436.   
  2437.   <Setter TargetName="Border" Property="Background" Value="{DynamicResource MaskColor}" />
  2438. 364
  2439.   
  2440.   
  2441.   
  2442.   
  2443.   
  2444.   </Trigger>
  2445. 365
  2446.   
  2447.   
  2448.   
  2449.   
  2450.   
  2451.   
  2452. 366
  2453.   
  2454.   
  2455.   
  2456.   
  2457.   
  2458.   <Trigger Property="Icon" Value="{x:Null}">
  2459. 367
  2460.   
  2461.   
  2462.   
  2463.   
  2464.   
  2465.   
  2466.   
  2467.   <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
  2468. 368
  2469.   
  2470.   
  2471.   
  2472.   
  2473.   
  2474.   </Trigger>
  2475. 369
  2476.   
  2477.   
  2478.   
  2479.   
  2480.   
  2481.   
  2482. 370
  2483.   
  2484.   
  2485.   
  2486.   
  2487.   
  2488.   <Trigger Property="IsCheckable" Value="True">
  2489. 371
  2490.   
  2491.   
  2492.   
  2493.   
  2494.   
  2495.   
  2496.   
  2497.   <Setter TargetName="CheckBoxIconBorder" Property="Visibility" Value="Visible" />
  2498. 372
  2499.   
  2500.   
  2501.   
  2502.   
  2503.   
  2504.   </Trigger>
  2505. 373
  2506.   
  2507.   
  2508.   
  2509.   
  2510.   
  2511.   
  2512. 374
  2513.   
  2514.   
  2515.   
  2516.   
  2517.   
  2518.   <Trigger Property="IsChecked" Value="True">
  2519. 375
  2520.   
  2521.   
  2522.   
  2523.   
  2524.   
  2525.   
  2526.   
  2527.   <Setter TargetName="CheckBoxIcon" Property="Data" Value="{StaticResource CheckGraph}" />
  2528. 376
  2529.   
  2530.   
  2531.   
  2532.   
  2533.   
  2534.   </Trigger>
  2535. 377
  2536.   
  2537.   
  2538.   
  2539.   
  2540.   
  2541.   
  2542. 378
  2543.   
  2544.   
  2545.   
  2546.   
  2547.   
  2548.   <Trigger Property="InputGestureText" Value="">
  2549. 379
  2550.   
  2551.   
  2552.   
  2553.   
  2554.   
  2555.   
  2556.   
  2557.   <Setter TargetName="InputGestureText" Property="Visibility" Value="Collapsed" />
  2558. 380
  2559.   
  2560.   
  2561.   
  2562.   
  2563.   
  2564.   </Trigger>
  2565. 381
  2566.   
  2567.   
  2568.   
  2569.   </ControlTemplate.Triggers>
  2570. 382
  2571.   
  2572.   </ControlTemplate>
  2573. 383
  2574. 384
  2575.   
  2576.   
  2577. 385
  2578.   
  2579.   <ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
  2580. 386
  2581.   
  2582.   
  2583.   
  2584.   <Grid>
  2585. 387
  2586.   
  2587.   
  2588.   
  2589.   
  2590.   
  2591.   <Grid.RowDefinitions>
  2592. 388
  2593.   
  2594.   
  2595.   
  2596.   
  2597.   
  2598.   
  2599.   
  2600.   <RowDefinition Height="*" />
  2601. 389
  2602.   
  2603.   
  2604.   
  2605.   
  2606.   
  2607.   
  2608.   
  2609.   <RowDefinition Height="Auto" />
  2610. 390
  2611.   
  2612.   
  2613.   
  2614.   
  2615.   
  2616.   </Grid.RowDefinitions>
  2617. 391
  2618. 392
  2619.   
  2620.   
  2621.   
  2622.   
  2623.   
  2624.   
  2625. 393
  2626.   
  2627.   
  2628.   
  2629.   
  2630.   
  2631.   <Border
  2632. 394
  2633.   
  2634.   
  2635.   
  2636.   
  2637.   
  2638.   
  2639.   
  2640.   x:Name="Border"
  2641. 395
  2642.   
  2643.   
  2644.   
  2645.   
  2646.   
  2647.   
  2648.   
  2649.   Grid.Row="1"
  2650. 396
  2651.   
  2652.   
  2653.   
  2654.   
  2655.   
  2656.   
  2657.   
  2658.   Height="{TemplateBinding Height}"
  2659. 397
  2660.   
  2661.   
  2662.   
  2663.   
  2664.   
  2665.   
  2666.   
  2667.   Margin="{StaticResource MenuItemMargin}"
  2668. 398
  2669.   
  2670.   
  2671.   
  2672.   
  2673.   
  2674.   
  2675.   
  2676.   Background="Transparent"
  2677. 399
  2678.   
  2679.   
  2680.   
  2681.   
  2682.   
  2683.   
  2684.   
  2685.   CornerRadius="{StaticResource MenuCornerRadius}">
  2686. 400
  2687.   
  2688.   
  2689.   
  2690.   
  2691.   
  2692.   
  2693.   
  2694.   <Grid x:Name="MenuItemContent" Margin="{StaticResource MenuItemContentPadding}">
  2695. 401
  2696.   
  2697.   
  2698.   
  2699.   
  2700.   
  2701.   
  2702.   
  2703.   
  2704.   
  2705.   <Grid.ColumnDefinitions>
  2706. 402
  2707.   
  2708.   
  2709.   
  2710.   
  2711.   
  2712.   
  2713.   
  2714.   
  2715.   
  2716.   
  2717.   
  2718.   <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemIconCol" />
  2719. 403
  2720.   
  2721.   
  2722.   
  2723.   
  2724.   
  2725.   
  2726.   
  2727.   
  2728.   
  2729.   
  2730.   
  2731.   <ColumnDefinition Width="*" />
  2732. 404
  2733.   
  2734.   
  2735.   
  2736.   
  2737.   
  2738.   
  2739.   
  2740.   
  2741.   
  2742.   
  2743.   
  2744.   <ColumnDefinition Width="Auto" SharedSizeGroup="MenuItemRightPartCol" />
  2745. 405
  2746.   
  2747.   
  2748.   
  2749.   
  2750.   
  2751.   
  2752.   
  2753.   
  2754.   
  2755.   </Grid.ColumnDefinitions>
  2756. 406
  2757. 407
  2758.   
  2759.   
  2760.   
  2761.   
  2762.   
  2763.   
  2764.   
  2765.   
  2766.   
  2767.   
  2768. 408
  2769.   
  2770.   
  2771.   
  2772.   
  2773.   
  2774.   
  2775.   
  2776.   
  2777.   
  2778.   <ContentPresenter
  2779. 409
  2780.   
  2781.   
  2782.   
  2783.   
  2784.   
  2785.   
  2786.   
  2787.   
  2788.   
  2789.   
  2790.   
  2791.   x:Name="Icon"
  2792. 410
  2793.   
  2794.   
  2795.   
  2796.   
  2797.   
  2798.   
  2799.   
  2800.   
  2801.   
  2802.   
  2803.   
  2804.   Grid.Column="0"
  2805. 411
  2806.   
  2807.   
  2808.   
  2809.   
  2810.   
  2811.   
  2812.   
  2813.   
  2814.   
  2815.   
  2816.   
  2817.   Margin="0,0,6,0"
  2818. 412
  2819.   
  2820.   
  2821.   
  2822.   
  2823.   
  2824.   
  2825.   
  2826.   
  2827.   
  2828.   
  2829.   
  2830.   VerticalAlignment="Center"
  2831. 413
  2832.   
  2833.   
  2834.   
  2835.   
  2836.   
  2837.   
  2838.   
  2839.   
  2840.   
  2841.   
  2842.   
  2843.   Content="{TemplateBinding Icon}"
  2844. 414
  2845.   
  2846.   
  2847.   
  2848.   
  2849.   
  2850.   
  2851.   
  2852.   
  2853.   
  2854.   
  2855.   
  2856.   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  2857. 415
  2858. 416
  2859.   
  2860.   
  2861.   
  2862.   
  2863.   
  2864.   
  2865.   
  2866.   
  2867.   
  2868.   
  2869. 417
  2870.   
  2871.   
  2872.   
  2873.   
  2874.   
  2875.   
  2876.   
  2877.   
  2878.   
  2879.   <ContentPresenter
  2880. 418
  2881.   
  2882.   
  2883.   
  2884.   
  2885.   
  2886.   
  2887.   
  2888.   
  2889.   
  2890.   
  2891.   
  2892.   x:Name="HeaderHost"
  2893. 419
  2894.   
  2895.   
  2896.   
  2897.   
  2898.   
  2899.   
  2900.   
  2901.   
  2902.   
  2903.   
  2904.   
  2905.   Grid.Column="1"
  2906. 420
  2907.   
  2908.   
  2909.   
  2910.   
  2911.   
  2912.   
  2913.   
  2914.   
  2915.   
  2916.   
  2917.   
  2918.   Margin="{TemplateBinding Padding}"
  2919. 421
  2920.   
  2921.   
  2922.   
  2923.   
  2924.   
  2925.   
  2926.   
  2927.   
  2928.   
  2929.   
  2930.   
  2931.   VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
  2932. 422
  2933.   
  2934.   
  2935.   
  2936.   
  2937.   
  2938.   
  2939.   
  2940.   
  2941.   
  2942.   
  2943.   
  2944.   ContentSource="Header"
  2945. 423
  2946.   
  2947.   
  2948.   
  2949.   
  2950.   
  2951.   
  2952.   
  2953.   
  2954.   
  2955.   
  2956.   
  2957.   RecognizesAccessKey="True"
  2958. 424
  2959.   
  2960.   
  2961.   
  2962.   
  2963.   
  2964.   
  2965.   
  2966.   
  2967.   
  2968.   
  2969.   
  2970.   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  2971. 425
  2972. 426
  2973.   
  2974.   
  2975.   
  2976.   
  2977.   
  2978.   
  2979.   
  2980.   
  2981.   
  2982.   
  2983. 427
  2984.   
  2985.   
  2986.   
  2987.   
  2988.   
  2989.   
  2990.   
  2991.   
  2992.   
  2993.   <Path
  2994. 428
  2995.   
  2996.   
  2997.   
  2998.   
  2999.   
  3000.   
  3001.   
  3002.   
  3003.   
  3004.   
  3005.   
  3006.   Grid.Column="2"
  3007. 429
  3008.   
  3009.   
  3010.   
  3011.   
  3012.   
  3013.   
  3014.   
  3015.   
  3016.   
  3017.   
  3018.   
  3019.   Width="10"
  3020. 430
  3021.   
  3022.   
  3023.   
  3024.   
  3025.   
  3026.   
  3027.   
  3028.   
  3029.   
  3030.   
  3031.   
  3032.   Height="10"
  3033. 431
  3034.   
  3035.   
  3036.   
  3037.   
  3038.   
  3039.   
  3040.   
  3041.   
  3042.   
  3043.   
  3044.   
  3045.   Margin="0,0,4,0"
  3046. 432
  3047.   
  3048.   
  3049.   
  3050.   
  3051.   
  3052.   
  3053.   
  3054.   
  3055.   
  3056.   
  3057.   
  3058.   HorizontalAlignment="Right"
  3059. 433
  3060.   
  3061.   
  3062.   
  3063.   
  3064.   
  3065.   
  3066.   
  3067.   
  3068.   
  3069.   
  3070.   
  3071.   VerticalAlignment="Center"
  3072. 434
  3073.   
  3074.   
  3075.   
  3076.   
  3077.   
  3078.   
  3079.   
  3080.   
  3081.   
  3082.   
  3083.   
  3084.   Data="{StaticResource ForwardGraph}"
  3085. 435
  3086.   
  3087.   
  3088.   
  3089.   
  3090.   
  3091.   
  3092.   
  3093.   
  3094.   
  3095.   
  3096.   
  3097.   Fill="{TemplateBinding Foreground}"
  3098. 436
  3099.   
  3100.   
  3101.   
  3102.   
  3103.   
  3104.   
  3105.   
  3106.   
  3107.   
  3108.   
  3109.   
  3110.   Opacity="0.67"
  3111. 437
  3112.   
  3113.   
  3114.   
  3115.   
  3116.   
  3117.   
  3118.   
  3119.   
  3120.   
  3121.   
  3122.   
  3123.   Stretch="Uniform" />
  3124. 438
  3125.   
  3126.   
  3127.   
  3128.   
  3129.   
  3130.   
  3131.   
  3132.   </Grid>
  3133. 439
  3134.   
  3135.   
  3136.   
  3137.   
  3138.   
  3139.   </Border>
  3140. 440
  3141. 441
  3142.   
  3143.   
  3144.   
  3145.   
  3146.   
  3147.   
  3148. 442
  3149.   
  3150.   
  3151.   
  3152.   
  3153.   
  3154.   <local:FluentPopup
  3155. 443
  3156.   
  3157.   
  3158.   
  3159.   
  3160.   
  3161.   
  3162.   
  3163.   x:Name="PART_Popup"
  3164. 444
  3165.   
  3166.   
  3167.   
  3168.   
  3169.   
  3170.   
  3171.   
  3172.   Grid.Row="1"
  3173. 445
  3174.   
  3175.   
  3176.   
  3177.   
  3178.   
  3179.   
  3180.   
  3181.   Focusable="False"
  3182. 446
  3183.   
  3184.   
  3185.   
  3186.   
  3187.   
  3188.   
  3189.   
  3190.   IsOpen="{TemplateBinding IsSubmenuOpen}"
  3191. 447
  3192.   
  3193.   
  3194.   
  3195.   
  3196.   
  3197.   
  3198.   
  3199.   Placement="Right"
  3200. 448
  3201.   
  3202.   
  3203.   
  3204.   
  3205.   
  3206.   
  3207.   
  3208.   PlacementTarget="{Binding ElementName=MenuItemContent}"
  3209. 449
  3210.   
  3211.   
  3212.   
  3213.   
  3214.   
  3215.   
  3216.   
  3217.   PopupAnimation="None">
  3218. 450
  3219.   
  3220.   
  3221.   
  3222.   
  3223.   
  3224.   
  3225.   
  3226.   <Grid x:Name="PopupRoot" Background="{DynamicResource PopupWindowBackground}">
  3227. 451
  3228.   
  3229.   
  3230.   
  3231.   
  3232.   
  3233.   
  3234.   
  3235.   
  3236.   
  3237.   
  3238. 452
  3239.   
  3240.   
  3241.   
  3242.   
  3243.   
  3244.   
  3245.   
  3246.   
  3247.   
  3248.   <Grid.RenderTransform>
  3249. 453
  3250.   
  3251.   
  3252.   
  3253.   
  3254.   
  3255.   
  3256.   
  3257.   
  3258.   
  3259.   
  3260.   
  3261.   <TranslateTransform />
  3262. 454
  3263.   
  3264.   
  3265.   
  3266.   
  3267.   
  3268.   
  3269.   
  3270.   
  3271.   
  3272.   </Grid.RenderTransform>
  3273. 455
  3274.   
  3275.   
  3276.   
  3277.   
  3278.   
  3279.   
  3280.   
  3281.   
  3282.   
  3283.   <ScrollViewer
  3284. 456
  3285.   
  3286.   
  3287.   
  3288.   
  3289.   
  3290.   
  3291.   
  3292.   
  3293.   
  3294.   
  3295.   
  3296.   Padding="{StaticResource MenuBorderPadding}"
  3297. 457
  3298.   
  3299.   
  3300.   
  3301.   
  3302.   
  3303.   
  3304.   
  3305.   
  3306.   
  3307.   
  3308.   
  3309.   CanContentScroll="True"
  3310. 458
  3311.   
  3312.   
  3313.   
  3314.   
  3315.   
  3316.   
  3317.   
  3318.   
  3319.   
  3320.   
  3321.   
  3322.   Style="{StaticResource MenuItemScrollViewerStyle}">
  3323. 459
  3324.   
  3325.   
  3326.   
  3327.   
  3328.   
  3329.   
  3330.   
  3331.   
  3332.   
  3333.   
  3334.   
  3335.   
  3336. 460
  3337.   
  3338.   
  3339.   
  3340.   
  3341.   
  3342.   
  3343.   
  3344.   
  3345.   
  3346.   
  3347.   
  3348.   <ItemsPresenter
  3349. 461
  3350.   
  3351.   
  3352.   
  3353.   
  3354.   
  3355.   
  3356.   
  3357.   
  3358.   
  3359.   
  3360.   
  3361.   
  3362.   
  3363.   x:Name="ItemsPresenter"
  3364. 462
  3365.   
  3366.   
  3367.   
  3368.   
  3369.   
  3370.   
  3371.   
  3372.   
  3373.   
  3374.   
  3375.   
  3376.   
  3377.   
  3378.   Grid.IsSharedSizeScope="True"
  3379. 463
  3380.   
  3381.   
  3382.   
  3383.   
  3384.   
  3385.   
  3386.   
  3387.   
  3388.   
  3389.   
  3390.   
  3391.   
  3392.   
  3393.   KeyboardNavigation.DirectionalNavigation="Cycle"
  3394. 464
  3395.   
  3396.   
  3397.   
  3398.   
  3399.   
  3400.   
  3401.   
  3402.   
  3403.   
  3404.   
  3405.   
  3406.   
  3407.   
  3408.   KeyboardNavigation.TabNavigation="Cycle"
  3409. 465
  3410.   
  3411.   
  3412.   
  3413.   
  3414.   
  3415.   
  3416.   
  3417.   
  3418.   
  3419.   
  3420.   
  3421.   
  3422.   
  3423.   SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
  3424. 466
  3425.   
  3426.   
  3427.   
  3428.   
  3429.   
  3430.   
  3431.   
  3432.   
  3433.   
  3434.   </ScrollViewer>
  3435. 467
  3436.   
  3437.   
  3438.   
  3439.   
  3440.   
  3441.   
  3442.   
  3443.   </Grid>
  3444. 468
  3445.   
  3446.   
  3447.   
  3448.   
  3449.   
  3450.   </local:FluentPopup>
  3451. 469
  3452.   
  3453.   
  3454.   
  3455.   </Grid>
  3456. 470
  3457.   
  3458.   
  3459.   
  3460.   <ControlTemplate.Triggers>
  3461. 471
  3462.   
  3463.   
  3464.   
  3465.   
  3466.   
  3467.   
  3468. 472
  3469.   
  3470.   
  3471.   
  3472.   
  3473.   
  3474.   <Trigger Property="Icon" Value="{x:Null}">
  3475. 473
  3476.   
  3477.   
  3478.   
  3479.   
  3480.   
  3481.   
  3482.   
  3483.   <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
  3484. 474
  3485.   
  3486.   
  3487.   
  3488.   
  3489.   
  3490.   
  3491.   
  3492.   <Setter TargetName="Icon" Property="Margin" Value="0" />
  3493. 475
  3494.   
  3495.   
  3496.   
  3497.   
  3498.   
  3499.   </Trigger>
  3500. 476
  3501.   
  3502.   
  3503.   
  3504.   
  3505.   
  3506.   
  3507. 477
  3508.   
  3509.   
  3510.   
  3511.   
  3512.   
  3513.   <Trigger Property="IsHighlighted" Value="true">
  3514. 478
  3515.   
  3516.   
  3517.   
  3518.   
  3519.   
  3520.   
  3521.   
  3522.   <Setter TargetName="Border" Property="Background" Value="{DynamicResource MaskColor}" />
  3523. 479
  3524.   
  3525.   
  3526.   
  3527.   
  3528.   
  3529.   </Trigger>
  3530. 480
  3531.   
  3532.   
  3533.   
  3534.   
  3535.   
  3536.   
  3537. 481
  3538.   
  3539.   
  3540.   
  3541.   
  3542.   
  3543.   <Trigger Property="IsSubmenuOpen" Value="True">
  3544. 482
  3545.   
  3546.   
  3547.   
  3548.   
  3549.   
  3550.   
  3551.   
  3552.   <Trigger.EnterActions>
  3553. 483
  3554.   
  3555.   
  3556.   
  3557.   
  3558.   
  3559.   
  3560.   
  3561.   
  3562.   
  3563.   <BeginStoryboard>
  3564. 484
  3565.   
  3566.   
  3567.   
  3568.   
  3569.   
  3570.   
  3571.   
  3572.   
  3573.   
  3574.   
  3575.   
  3576.   <Storyboard>
  3577. 485
  3578.   
  3579.   
  3580.   
  3581.   
  3582.   
  3583.   
  3584.   
  3585.   
  3586.   
  3587.   
  3588.   
  3589.   
  3590.   
  3591.   
  3592. 486
  3593.   
  3594.   
  3595.   
  3596.   
  3597.   
  3598.   
  3599.   
  3600.   
  3601.   
  3602.   
  3603.   
  3604.   
  3605.   
  3606.   <DoubleAnimation
  3607. 487
  3608.   
  3609.   
  3610.   
  3611.   
  3612.   
  3613.   
  3614.   
  3615.   
  3616.   
  3617.   
  3618.   
  3619.   
  3620.   
  3621.   
  3622.   
  3623.   Storyboard.TargetName="PopupRoot"
  3624. 488
  3625.   
  3626.   
  3627.   
  3628.   
  3629.   
  3630.   
  3631.   
  3632.   
  3633.   
  3634.   
  3635.   
  3636.   
  3637.   
  3638.   
  3639.   
  3640.   Storyboard.TargetProperty="(Grid.RenderTransform).(TranslateTransform.Y)"
  3641. 489
  3642.   
  3643.   
  3644.   
  3645.   
  3646.   
  3647.   
  3648.   
  3649.   
  3650.   
  3651.   
  3652.   
  3653.   
  3654.   
  3655.   
  3656.   
  3657.   From="-45"
  3658. 490
  3659.   
  3660.   
  3661.   
  3662.   
  3663.   
  3664.   
  3665.   
  3666.   
  3667.   
  3668.   
  3669.   
  3670.   
  3671.   
  3672.   
  3673.   
  3674.   To="0"
  3675. 491
  3676.   
  3677.   
  3678.   
  3679.   
  3680.   
  3681.   
  3682.   
  3683.   
  3684.   
  3685.   
  3686.   
  3687.   
  3688.   
  3689.   
  3690.   
  3691.   Duration="{StaticResource MenuAnimationDuration}">
  3692. 492
  3693.   
  3694.   
  3695.   
  3696.   
  3697.   
  3698.   
  3699.   
  3700.   
  3701.   
  3702.   
  3703.   
  3704.   
  3705.   
  3706.   
  3707.   
  3708.   <DoubleAnimation.EasingFunction>
  3709. 493
  3710.   
  3711.   
  3712.   
  3713.   
  3714.   
  3715.   
  3716.   
  3717.   
  3718.   
  3719.   
  3720.   
  3721.   
  3722.   
  3723.   
  3724.   
  3725.   
  3726.   
  3727.   <CircleEase EasingMode="EaseOut" />
  3728. 494
  3729.   
  3730.   
  3731.   
  3732.   
  3733.   
  3734.   
  3735.   
  3736.   
  3737.   
  3738.   
  3739.   
  3740.   
  3741.   
  3742.   
  3743.   
  3744.   </DoubleAnimation.EasingFunction>
  3745. 495
  3746.   
  3747.   
  3748.   
  3749.   
  3750.   
  3751.   
  3752.   
  3753.   
  3754.   
  3755.   
  3756.   
  3757.   
  3758.   
  3759.   </DoubleAnimation>
  3760. 496
  3761.   
  3762.   
  3763.   
  3764.   
  3765.   
  3766.   
  3767.   
  3768.   
  3769.   
  3770.   
  3771.   
  3772.   </Storyboard>
  3773. 497
  3774.   
  3775.   
  3776.   
  3777.   
  3778.   
  3779.   
  3780.   
  3781.   
  3782.   
  3783.   </BeginStoryboard>
  3784. 498
  3785.   
  3786.   
  3787.   
  3788.   
  3789.   
  3790.   
  3791.   
  3792.   </Trigger.EnterActions>
  3793. 499
  3794.   
  3795.   
  3796.   
  3797.   
  3798.   
  3799.   </Trigger>
  3800. 500
  3801.   
  3802.   
  3803.   
  3804.   </ControlTemplate.Triggers>
  3805. 501
  3806.   
  3807.   </ControlTemplate>
  3808. 502
  3809. 503
  3810.   
  3811.   
  3812. 504
  3813.   
  3814.   
  3815. 539
  3816. 540 </ResourceDictionary>
复制代码
View Code三、应用模板和样式到全局

将上面的资源字典归并到应用步调资源中,然后为ContextMenu和MenuItem指定默认样式:
复制代码
注意,ContextMenu必要利用之前文章中的FluentTooltip.UseFluentStyle来实现亚克力材质殊效。其内部原理都是反射获取popup的hwnd句柄,然后附加WindowMaterial殊效。
参考文档

1. ContextMenu Styles and Templates WPF | Microsoft Learn
2. Menu Styles and Templates WPF | Microsoft Learn
3. PresentationFramework.Fluent/Themes/Fluent.xaml | GitHub
 
 

  本作品接纳 知识共享署名-非贸易性利用-雷同方式共享 4.0 国际允许协议 举行允许。欢迎转载、利用、重新发布,但务必生存文章署名TwilightLemon(https://blog.twlmgatito.cn),不得用于贸易目的,基于本文修改后的作品务必以雷同的允许发布。
文章及其代码堆栈大概不时更新,检察原文:WPF 为ContextMenu利用Fluent风格的亚克力材质殊效 - Twlm's Blog
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表