- A+
所属分类:.NET技术
1 <SolidColorBrush 2 x:Key="Menu.Static.Background" 3 Color="#FFF0F0F0" /> 4 <SolidColorBrush 5 x:Key="Menu.Static.Border" 6 Color="#FF999999" /> 7 <SolidColorBrush 8 x:Key="Menu.Static.Foreground" 9 Color="#FF212121" /> 10 <SolidColorBrush 11 x:Key="Menu.Static.Separator" 12 Color="#FFD7D7D7" /> 13 <SolidColorBrush 14 x:Key="Menu.Disabled.Foreground" 15 Color="#FF707070" /> 16 <SolidColorBrush 17 x:Key="MenuItem.Selected.Background" 18 Color="#3D26A0DA" /> 19 <SolidColorBrush 20 x:Key="MenuItem.Selected.Border" 21 Color="#FF26A0DA" /> 22 <SolidColorBrush 23 x:Key="MenuItem.Highlight.Background" 24 Color="#3D26A0DA" /> 25 <SolidColorBrush 26 x:Key="MenuItem.Highlight.Border" 27 Color="#FF26A0DA" /> 28 <SolidColorBrush 29 x:Key="MenuItem.Highlight.Disabled.Background" 30 Color="#0A000000" /> 31 <SolidColorBrush 32 x:Key="MenuItem.Highlight.Disabled.Border" 33 Color="#21000000" /> 34 <MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" /> 35 <Geometry x:Key="DownArrow">M 0,0 L 3.5,4 L 7,0 Z</Geometry> 36 <Geometry x:Key="UpArrow">M 0,4 L 3.5,0 L 7,4 Z</Geometry> 37 <Geometry x:Key="RightArrow">M 0,0 L 4,3.5 L 0,7 Z</Geometry> 38 <Geometry x:Key="Checkmark">F1 M 10.0,1.2 L 4.7,9.1 L 4.5,9.1 L 0,5.2 L 1.3,3.5 L 4.3,6.1L 8.3,0 L 10.0,1.2 Z</Geometry> 39 40 <Style 41 x:Key="MenuScrollButton" 42 BasedOn="{x:Null}" 43 TargetType="{x:Type RepeatButton}"> 44 <Setter Property="ClickMode" Value="Hover" /> 45 <Setter Property="Template"> 46 <Setter.Value> 47 <ControlTemplate TargetType="{x:Type RepeatButton}"> 48 <Border 49 x:Name="templateRoot" 50 Background="Transparent" 51 BorderBrush="Transparent" 52 BorderThickness="1" 53 SnapsToDevicePixels="true"> 54 <ContentPresenter 55 Margin="6" 56 HorizontalAlignment="Center" 57 VerticalAlignment="Center" /> 58 </Border> 59 </ControlTemplate> 60 </Setter.Value> 61 </Setter> 62 </Style> 63 64 65 <!-- 弹出的子菜单中 ScrollViewer 的样式,用于在菜单项较多时,上下滚动显示所有的菜单项 --> 66 <Style 67 x:Key="{ComponentResourceKey ResourceId=MenuScrollViewer, 68 TypeInTargetAssembly={x:Type FrameworkElement}}" 69 BasedOn="{x:Null}" 70 TargetType="{x:Type ScrollViewer}"> 71 <Setter Property="HorizontalScrollBarVisibility" Value="Hidden" /> 72 <Setter Property="VerticalScrollBarVisibility" Value="Auto" /> 73 <Setter Property="Template"> 74 <Setter.Value> 75 <ControlTemplate TargetType="{x:Type ScrollViewer}"> 76 <Grid SnapsToDevicePixels="true"> 77 <Grid.ColumnDefinitions> 78 <ColumnDefinition Width="*" /> 79 </Grid.ColumnDefinitions> 80 81 <Grid.RowDefinitions> 82 <RowDefinition Height="Auto" /> 83 <RowDefinition Height="*" /> 84 <RowDefinition Height="Auto" /> 85 </Grid.RowDefinitions> 86 87 <!-- 所有的菜单内容 --> 88 <Border 89 Grid.Row="1" 90 Grid.Column="0"> 91 <ScrollContentPresenter 92 Margin="{TemplateBinding Padding}" 93 CanContentScroll="{TemplateBinding CanContentScroll}" /> 94 </Border> 95 96 <!-- 向上滚动按钮 --> 97 <RepeatButton 98 Grid.Row="0" 99 Grid.Column="0" 100 Command="{x:Static ScrollBar.LineUpCommand}" 101 CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" 102 Focusable="false" 103 Style="{StaticResource MenuScrollButton}"> 104 <RepeatButton.Visibility> 105 <MultiBinding 106 Converter="{StaticResource MenuScrollingVisibilityConverter}" 107 ConverterParameter="0" 108 FallbackValue="Visibility.Collapsed"> 109 <Binding 110 Path="ComputedVerticalScrollBarVisibility" 111 RelativeSource="{RelativeSource TemplatedParent}" /> 112 <Binding 113 Path="VerticalOffset" 114 RelativeSource="{RelativeSource TemplatedParent}" /> 115 <Binding 116 Path="ExtentHeight" 117 RelativeSource="{RelativeSource TemplatedParent}" /> 118 <Binding 119 Path="ViewportHeight" 120 RelativeSource="{RelativeSource TemplatedParent}" /> 121 </MultiBinding> 122 </RepeatButton.Visibility> 123 <Path 124 Data="{StaticResource UpArrow}" 125 Fill="{StaticResource Menu.Static.Foreground}" /> 126 </RepeatButton> 127 128 <!-- 向下滚动按钮 --> 129 <RepeatButton 130 Grid.Row="2" 131 Grid.Column="0" 132 Command="{x:Static ScrollBar.LineDownCommand}" 133 CommandTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" 134 Focusable="false" 135 Style="{StaticResource MenuScrollButton}"> 136 <RepeatButton.Visibility> 137 <MultiBinding 138 Converter="{StaticResource MenuScrollingVisibilityConverter}" 139 ConverterParameter="100" 140 FallbackValue="Visibility.Collapsed"> 141 <Binding 142 Path="ComputedVerticalScrollBarVisibility" 143 RelativeSource="{RelativeSource TemplatedParent}" /> 144 <Binding 145 Path="VerticalOffset" 146 RelativeSource="{RelativeSource TemplatedParent}" /> 147 <Binding 148 Path="ExtentHeight" 149 RelativeSource="{RelativeSource TemplatedParent}" /> 150 <Binding 151 Path="ViewportHeight" 152 RelativeSource="{RelativeSource TemplatedParent}" /> 153 </MultiBinding> 154 </RepeatButton.Visibility> 155 <Path 156 Data="{StaticResource DownArrow}" 157 Fill="{StaticResource Menu.Static.Foreground}" /> 158 </RepeatButton> 159 </Grid> 160 </ControlTemplate> 161 </Setter.Value> 162 </Setter> 163 </Style> 164 165 <!-- Role 的文档详见 https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.menuitemrole?view=windowsdesktop-6.0 --> 166 167 <!-- 当 Role= TopLevelItem 时的模版 --> 168 <ControlTemplate 169 x:Key="{ComponentResourceKey ResourceId=TopLevelItemTemplateKey, 170 TypeInTargetAssembly={x:Type MenuItem}}" 171 TargetType="{x:Type MenuItem}"> 172 <Border 173 x:Name="templateRoot" 174 Background="{TemplateBinding Background}" 175 BorderBrush="{TemplateBinding BorderBrush}" 176 BorderThickness="{TemplateBinding BorderThickness}" 177 SnapsToDevicePixels="true"> 178 <Grid VerticalAlignment="Center"> 179 <Grid.ColumnDefinitions> 180 <ColumnDefinition Width="Auto" /> 181 <ColumnDefinition Width="Auto" /> 182 </Grid.ColumnDefinitions> 183 <ContentPresenter 184 x:Name="Icon" 185 Width="16" 186 Height="16" 187 Margin="3" 188 HorizontalAlignment="Center" 189 VerticalAlignment="Center" 190 ContentSource="Icon" 191 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 192 <Path 193 x:Name="GlyphPanel" 194 Margin="3" 195 VerticalAlignment="Center" 196 Data="{StaticResource Checkmark}" 197 Fill="{StaticResource Menu.Static.Foreground}" 198 FlowDirection="LeftToRight" 199 Visibility="Collapsed" /> 200 <ContentPresenter 201 Grid.Column="1" 202 Margin="{TemplateBinding Padding}" 203 ContentSource="Header" 204 RecognizesAccessKey="True" 205 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 206 </Grid> 207 </Border> 208 <ControlTemplate.Triggers> 209 <Trigger Property="Icon" Value="{x:Null}"> 210 <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" /> 211 </Trigger> 212 <Trigger Property="IsChecked" Value="true"> 213 <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" /> 214 <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" /> 215 </Trigger> 216 <Trigger Property="IsHighlighted" Value="True"> 217 <Setter TargetName="templateRoot" Property="Background" Value="{StaticResource MenuItem.Highlight.Background}" /> 218 <Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource MenuItem.Highlight.Border}" /> 219 </Trigger> 220 <Trigger Property="IsEnabled" Value="False"> 221 <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{StaticResource Menu.Disabled.Foreground}" /> 222 <Setter TargetName="GlyphPanel" Property="Fill" Value="{StaticResource Menu.Disabled.Foreground}" /> 223 </Trigger> 224 <MultiTrigger> 225 <MultiTrigger.Conditions> 226 <Condition Property="IsHighlighted" Value="True" /> 227 <Condition Property="IsEnabled" Value="False" /> 228 </MultiTrigger.Conditions> 229 <Setter TargetName="templateRoot" Property="Background" Value="{StaticResource MenuItem.Highlight.Disabled.Background}" /> 230 <Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource MenuItem.Highlight.Disabled.Border}" /> 231 </MultiTrigger> 232 </ControlTemplate.Triggers> 233 </ControlTemplate> 234 235 <!-- 当 Role= TopLevelHeader 时的模版 --> 236 <ControlTemplate 237 x:Key="{ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, 238 TypeInTargetAssembly={x:Type MenuItem}}" 239 TargetType="{x:Type MenuItem}"> 240 <Border 241 x:Name="templateRoot" 242 Background="{TemplateBinding Background}" 243 BorderBrush="{TemplateBinding BorderBrush}" 244 BorderThickness="{TemplateBinding BorderThickness}" 245 SnapsToDevicePixels="true"> 246 <Grid VerticalAlignment="Center"> 247 <Grid.ColumnDefinitions> 248 <ColumnDefinition Width="Auto" /> 249 <ColumnDefinition Width="Auto" /> 250 </Grid.ColumnDefinitions> 251 <ContentPresenter 252 x:Name="Icon" 253 Width="16" 254 Height="16" 255 Margin="3" 256 HorizontalAlignment="Center" 257 VerticalAlignment="Center" 258 ContentSource="Icon" 259 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 260 <Path 261 x:Name="GlyphPanel" 262 Margin="3" 263 VerticalAlignment="Center" 264 Data="{StaticResource Checkmark}" 265 Fill="{TemplateBinding Foreground}" 266 FlowDirection="LeftToRight" 267 Visibility="Collapsed" /> 268 <ContentPresenter 269 Grid.Column="1" 270 Margin="{TemplateBinding Padding}" 271 ContentSource="Header" 272 RecognizesAccessKey="True" 273 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 274 <Popup 275 x:Name="PART_Popup" 276 AllowsTransparency="true" 277 Focusable="false" 278 IsOpen="{Binding IsSubmenuOpen, 279 RelativeSource={RelativeSource TemplatedParent}}" 280 Placement="Bottom" 281 PlacementTarget="{Binding ElementName=templateRoot}" 282 PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"> 283 284 <!-- 弹出的子菜单 --> 285 <Border 286 x:Name="SubMenuBorder" 287 Padding="2" 288 Background="{StaticResource Menu.Static.Background}" 289 BorderBrush="{StaticResource Menu.Static.Border}" 290 BorderThickness="1"> 291 <ScrollViewer 292 x:Name="SubMenuScrollViewer" 293 Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, 294 TypeInTargetAssembly={x:Type FrameworkElement}}}"> 295 <Grid RenderOptions.ClearTypeHint="Enabled"> 296 <Canvas 297 Width="0" 298 Height="0" 299 HorizontalAlignment="Left" 300 VerticalAlignment="Top"> 301 <Rectangle 302 x:Name="OpaqueRect" 303 Width="{Binding ActualWidth, 304 ElementName=SubMenuBorder}" 305 Height="{Binding ActualHeight, 306 ElementName=SubMenuBorder}" 307 Fill="{Binding Background, 308 ElementName=SubMenuBorder}" /> 309 </Canvas> 310 <Rectangle 311 Width="1" 312 Margin="29,2,0,2" 313 HorizontalAlignment="Left" 314 Fill="{StaticResource Menu.Static.Separator}" /> 315 <ItemsPresenter 316 x:Name="ItemsPresenter" 317 Grid.IsSharedSizeScope="true" 318 KeyboardNavigation.DirectionalNavigation="Cycle" 319 KeyboardNavigation.TabNavigation="Cycle" 320 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 321 </Grid> 322 </ScrollViewer> 323 </Border> 324 </Popup> 325 </Grid> 326 </Border> 327 <ControlTemplate.Triggers> 328 <Trigger Property="IsSuspendingPopupAnimation" Value="true"> 329 <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None" /> 330 </Trigger> 331 <Trigger Property="Icon" Value="{x:Null}"> 332 <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" /> 333 </Trigger> 334 <Trigger Property="IsChecked" Value="true"> 335 <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" /> 336 <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" /> 337 </Trigger> 338 <Trigger Property="IsHighlighted" Value="True"> 339 <Setter TargetName="templateRoot" Property="Background" Value="{StaticResource MenuItem.Highlight.Background}" /> 340 <Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource MenuItem.Highlight.Border}" /> 341 </Trigger> 342 <Trigger Property="IsEnabled" Value="False"> 343 <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{StaticResource Menu.Disabled.Foreground}" /> 344 <Setter TargetName="GlyphPanel" Property="Fill" Value="{StaticResource Menu.Disabled.Foreground}" /> 345 </Trigger> 346 <Trigger SourceName="SubMenuScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false"> 347 <Setter TargetName="OpaqueRect" Property="Canvas.Top" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}" /> 348 <Setter TargetName="OpaqueRect" Property="Canvas.Left" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}" /> 349 </Trigger> 350 </ControlTemplate.Triggers> 351 </ControlTemplate> 352 353 <!-- MenuItem 常规的模版 --> 354 <ControlTemplate 355 x:Key="{ComponentResourceKey ResourceId=SubmenuItemTemplateKey, 356 TypeInTargetAssembly={x:Type MenuItem}}" 357 TargetType="{x:Type MenuItem}"> 358 <Border 359 x:Name="templateRoot" 360 Height="22" 361 Background="{TemplateBinding Background}" 362 BorderBrush="{TemplateBinding BorderBrush}" 363 BorderThickness="{TemplateBinding BorderThickness}" 364 SnapsToDevicePixels="true"> 365 <Grid Margin="-1"> 366 <!-- 布局 0~5 共 6 列, 其中 1,3,5 用作留空 --> 367 <Grid.ColumnDefinitions> 368 <ColumnDefinition 369 Width="Auto" 370 MinWidth="22" 371 SharedSizeGroup="MenuItemIconColumnGroup" /> 372 <ColumnDefinition Width="13" /> 373 <ColumnDefinition Width="*" /> 374 <ColumnDefinition Width="30" /> 375 <ColumnDefinition 376 Width="Auto" 377 SharedSizeGroup="MenuItemIGTColumnGroup" /> 378 <ColumnDefinition Width="20" /> 379 </Grid.ColumnDefinitions> 380 381 <!-- 第 0 列 图标 --> 382 <ContentPresenter 383 x:Name="Icon" 384 Width="16" 385 Height="16" 386 Margin="3" 387 HorizontalAlignment="Center" 388 VerticalAlignment="Center" 389 ContentSource="Icon" 390 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 391 392 <!-- 第 0 列,勾(用于标识是否勾选) --> 393 <Border 394 x:Name="GlyphPanel" 395 Width="22" 396 Height="22" 397 Margin="-1,0,0,0" 398 HorizontalAlignment="Center" 399 VerticalAlignment="Center" 400 Background="{StaticResource MenuItem.Selected.Background}" 401 BorderBrush="{StaticResource MenuItem.Selected.Border}" 402 BorderThickness="1" 403 ClipToBounds="False" 404 Visibility="Hidden"> 405 <Path 406 x:Name="Glyph" 407 Width="10" 408 Height="11" 409 Data="{StaticResource Checkmark}" 410 Fill="{StaticResource Menu.Static.Foreground}" 411 FlowDirection="LeftToRight" /> 412 </Border> 413 414 <!-- 第 2 列 MenuItem.Header 的内容 --> 415 <ContentPresenter 416 x:Name="menuHeaderContainer" 417 Grid.Column="2" 418 Margin="{TemplateBinding Padding}" 419 HorizontalAlignment="Left" 420 VerticalAlignment="Center" 421 ContentSource="Header" 422 RecognizesAccessKey="True" 423 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 424 425 <!-- 第 4 列 MenuItem.menuGestureText 的内容 --> 426 <TextBlock 427 x:Name="menuGestureText" 428 Grid.Column="4" 429 Margin="{TemplateBinding Padding}" 430 VerticalAlignment="Center" 431 Opacity="0.7" 432 Text="{TemplateBinding InputGestureText}" /> 433 </Grid> 434 </Border> 435 <ControlTemplate.Triggers> 436 <!-- 有图标的时候显示图标,没图标则隐藏 --> 437 <Trigger Property="Icon" Value="{x:Null}"> 438 <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" /> 439 </Trigger> 440 441 <!-- 被勾选时显示勾选,并且隐藏图标 --> 442 <Trigger Property="IsChecked" Value="True"> 443 <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" /> 444 <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" /> 445 </Trigger> 446 447 <!-- 高亮时 改变背景色和边框色 --> 448 <Trigger Property="IsHighlighted" Value="True"> 449 <Setter TargetName="templateRoot" Property="Background" Value="{StaticResource MenuItem.Highlight.Background}" /> 450 <Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource MenuItem.Highlight.Border}" /> 451 </Trigger> 452 453 <!-- 不可用时 将文字内容和勾设为禁用色 --> 454 <Trigger Property="IsEnabled" Value="False"> 455 <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{StaticResource Menu.Disabled.Foreground}" /> 456 <Setter TargetName="Glyph" Property="Fill" Value="{StaticResource Menu.Disabled.Foreground}" /> 457 </Trigger> 458 459 <!-- 高亮且禁用时 改变背景色和边框色 --> 460 <MultiTrigger> 461 <MultiTrigger.Conditions> 462 <Condition Property="IsHighlighted" Value="True" /> 463 <Condition Property="IsEnabled" Value="False" /> 464 </MultiTrigger.Conditions> 465 <Setter TargetName="templateRoot" Property="Background" Value="{StaticResource MenuItem.Highlight.Disabled.Background}" /> 466 <Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource MenuItem.Highlight.Disabled.Border}" /> 467 </MultiTrigger> 468 </ControlTemplate.Triggers> 469 </ControlTemplate> 470 471 <!-- 当 Role= SubmenuHeader 即有子菜单时的模版 --> 472 <!-- 与常规模版的主要区别是增加了子菜单的 popup 和弹出动画等 --> 473 <ControlTemplate 474 x:Key="{ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, 475 TypeInTargetAssembly={x:Type MenuItem}}" 476 TargetType="{x:Type MenuItem}"> 477 <Border 478 x:Name="templateRoot" 479 Height="22" 480 Background="{TemplateBinding Background}" 481 BorderBrush="{TemplateBinding BorderBrush}" 482 BorderThickness="{TemplateBinding BorderThickness}" 483 SnapsToDevicePixels="true"> 484 <Grid Margin="-1"> 485 <Grid.ColumnDefinitions> 486 <ColumnDefinition 487 Width="Auto" 488 MinWidth="22" 489 SharedSizeGroup="MenuItemIconColumnGroup" /> 490 <ColumnDefinition Width="13" /> 491 <ColumnDefinition Width="*" /> 492 <ColumnDefinition Width="30" /> 493 <ColumnDefinition 494 Width="Auto" 495 SharedSizeGroup="MenuItemIGTColumnGroup" /> 496 <ColumnDefinition Width="20" /> 497 </Grid.ColumnDefinitions> 498 <ContentPresenter 499 x:Name="Icon" 500 Width="16" 501 Height="16" 502 Margin="3" 503 HorizontalAlignment="Center" 504 VerticalAlignment="Center" 505 ContentSource="Icon" 506 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 507 <Border 508 x:Name="GlyphPanel" 509 Width="22" 510 Height="22" 511 Margin="-1,0,0,0" 512 VerticalAlignment="Center" 513 Background="{StaticResource MenuItem.Highlight.Background}" 514 BorderBrush="{StaticResource MenuItem.Highlight.Border}" 515 BorderThickness="1" 516 Visibility="Hidden"> 517 <Path 518 x:Name="Glyph" 519 Width="9" 520 Height="11" 521 Data="{DynamicResource Checkmark}" 522 Fill="{StaticResource Menu.Static.Foreground}" 523 FlowDirection="LeftToRight" /> 524 </Border> 525 <ContentPresenter 526 Grid.Column="2" 527 Margin="{TemplateBinding Padding}" 528 HorizontalAlignment="Left" 529 VerticalAlignment="Center" 530 ContentSource="Header" 531 RecognizesAccessKey="True" 532 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 533 <TextBlock 534 Grid.Column="4" 535 Margin="{TemplateBinding Padding}" 536 VerticalAlignment="Center" 537 Opacity="0.7" 538 Text="{TemplateBinding InputGestureText}" /> 539 <Path 540 x:Name="RightArrow" 541 Grid.Column="5" 542 Margin="10,0,0,0" 543 HorizontalAlignment="Left" 544 VerticalAlignment="Center" 545 Data="{StaticResource RightArrow}" 546 Fill="{StaticResource Menu.Static.Foreground}" /> 547 <Popup 548 x:Name="PART_Popup" 549 AllowsTransparency="true" 550 Focusable="false" 551 HorizontalOffset="-2" 552 IsOpen="{Binding IsSubmenuOpen, 553 RelativeSource={RelativeSource TemplatedParent}}" 554 Placement="Right" 555 PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" 556 VerticalOffset="-3"> 557 558 <Border 559 x:Name="SubMenuBorder" 560 Padding="2" 561 Background="{StaticResource Menu.Static.Background}" 562 BorderBrush="{StaticResource Menu.Static.Border}" 563 BorderThickness="1"> 564 <ScrollViewer 565 x:Name="SubMenuScrollViewer" 566 Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, 567 TypeInTargetAssembly={x:Type FrameworkElement}}}"> 568 <Grid RenderOptions.ClearTypeHint="Enabled"> 569 <Canvas 570 Width="0" 571 Height="0" 572 HorizontalAlignment="Left" 573 VerticalAlignment="Top"> 574 <Rectangle 575 x:Name="OpaqueRect" 576 Width="{Binding ActualWidth, 577 ElementName=SubMenuBorder}" 578 Height="{Binding ActualHeight, 579 ElementName=SubMenuBorder}" 580 Fill="{Binding Background, 581 ElementName=SubMenuBorder}" /> 582 </Canvas> 583 <Rectangle 584 Width="1" 585 Margin="29,2,0,2" 586 HorizontalAlignment="Left" 587 Fill="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}" /> 588 <ItemsPresenter 589 x:Name="ItemsPresenter" 590 Grid.IsSharedSizeScope="true" 591 KeyboardNavigation.DirectionalNavigation="Cycle" 592 KeyboardNavigation.TabNavigation="Cycle" 593 SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 594 </Grid> 595 </ScrollViewer> 596 </Border> 597 </Popup> 598 </Grid> 599 </Border> 600 <ControlTemplate.Triggers> 601 <Trigger Property="IsSuspendingPopupAnimation" Value="true"> 602 <Setter TargetName="PART_Popup" Property="PopupAnimation" Value="None" /> 603 </Trigger> 604 <Trigger Property="Icon" Value="{x:Null}"> 605 <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" /> 606 </Trigger> 607 <Trigger Property="IsChecked" Value="True"> 608 <Setter TargetName="GlyphPanel" Property="Visibility" Value="Visible" /> 609 <Setter TargetName="Icon" Property="Visibility" Value="Collapsed" /> 610 </Trigger> 611 <Trigger Property="IsHighlighted" Value="True"> 612 <Setter TargetName="templateRoot" Property="Background" Value="Transparent" /> 613 <Setter TargetName="templateRoot" Property="BorderBrush" Value="{StaticResource MenuItem.Highlight.Border}" /> 614 </Trigger> 615 <Trigger Property="IsEnabled" Value="False"> 616 <Setter TargetName="templateRoot" Property="TextElement.Foreground" Value="{StaticResource Menu.Disabled.Foreground}" /> 617 <Setter TargetName="Glyph" Property="Fill" Value="{StaticResource Menu.Disabled.Foreground}" /> 618 <Setter TargetName="RightArrow" Property="Fill" Value="{StaticResource Menu.Disabled.Foreground}" /> 619 </Trigger> 620 <Trigger SourceName="SubMenuScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false"> 621 <Setter TargetName="OpaqueRect" Property="Canvas.Top" Value="{Binding VerticalOffset, ElementName=SubMenuScrollViewer}" /> 622 <Setter TargetName="OpaqueRect" Property="Canvas.Left" Value="{Binding HorizontalOffset, ElementName=SubMenuScrollViewer}" /> 623 </Trigger> 624 </ControlTemplate.Triggers> 625 </ControlTemplate> 626 627 <Style 628 x:Key="MenuItemStyle1" 629 TargetType="{x:Type MenuItem}"> 630 <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" /> 631 <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" /> 632 <Setter Property="Background" Value="Transparent" /> 633 <Setter Property="BorderBrush" Value="Transparent" /> 634 <Setter Property="BorderThickness" Value="1" /> 635 <Setter Property="ScrollViewer.PanningMode" Value="Both" /> 636 <Setter Property="Stylus.IsFlicksEnabled" Value="False" /> 637 <!-- MenuItem 的常规版 --> 638 <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" /> 639 640 <Style.Triggers> 641 <Trigger Property="Role" Value="TopLevelHeader"> 642 <Setter Property="Background" Value="Transparent" /> 643 <Setter Property="BorderBrush" Value="Transparent" /> 644 <Setter Property="Foreground" Value="{StaticResource Menu.Static.Foreground}" /> 645 <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" /> 646 <Setter Property="Padding" Value="6,0" /> 647 </Trigger> 648 <Trigger Property="Role" Value="TopLevelItem"> 649 <Setter Property="Background" Value="{StaticResource Menu.Static.Background}" /> 650 <Setter Property="BorderBrush" Value="{StaticResource Menu.Static.Border}" /> 651 <Setter Property="Foreground" Value="{StaticResource Menu.Static.Foreground}" /> 652 <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TopLevelItemTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" /> 653 <Setter Property="Padding" Value="6,0" /> 654 </Trigger> 655 656 <!-- 当 Role= SubmenuHeader 时 改变模版为 SubmenuHeaderTemplateKey --> 657 <Trigger Property="Role" Value="SubmenuHeader"> 658 <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=SubmenuHeaderTemplateKey, TypeInTargetAssembly={x:Type MenuItem}}}" /> 659 </Trigger> 660 </Style.Triggers> 661 </Style>