ContextMenuStrip.xaml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <ContextMenu x:Class="CustomControls.ContextMenuStrip" Style="{DynamicResource ContextMenuStyle1}"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:s="clr-namespace:System;assembly=mscorlib"
  5. xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
  6. xmlns:local="clr-namespace:CustomControls">
  7. <ContextMenu.Resources>
  8. <SolidColorBrush x:Key="Menu.Static.Border" Color="Gray"/>
  9. <SolidColorBrush x:Key="Menu.Static.Background" Color="White"/>
  10. <SolidColorBrush x:Key="Menu.Margin.Background" Color="#FFF1F1F1"/>
  11. <SolidColorBrush x:Key="Menu.QAT.Background" Color="Transparent"/>
  12. <Style x:Key="ContextMenuStyle1" TargetType="{x:Type ContextMenu}">
  13. <Setter Property="VerticalOffset" Value="-1"/>
  14. <Setter Property="Template">
  15. <Setter.Value>
  16. <ControlTemplate TargetType="{x:Type ContextMenu}" >
  17. <mwt:SystemDropShadowChrome Color="#00FFFFFF" Name="Shdw" SnapsToDevicePixels="True">
  18. <StackPanel Orientation="Vertical">
  19. <Border x:Name="ToolBarBorder" Background="{DynamicResource Menu.Static.Background}" BorderThickness="1" Margin="0,0,0,1" BorderBrush="Transparent" Visibility="Collapsed">
  20. <local:ToolStrip x:Name="ToolBar" Height="26" GripVisible="False" Background="{DynamicResource Menu.QAT.Background}"/>
  21. </Border>
  22. <Border Background="{DynamicResource Menu.Static.Background}" BorderThickness="{TemplateBinding Border.BorderThickness}" BorderBrush="{DynamicResource Menu.Static.Border}" Name="ContextMenuBorder">
  23. <ScrollViewer Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly=FrameworkElement, ResourceId=MenuScrollViewer}}" Name="ContextMenuScrollViewer" Margin="1,0,1,0" Grid.ColumnSpan="2">
  24. <Grid>
  25. <Canvas Width="0" Height="0" HorizontalAlignment="Left" VerticalAlignment="Top">
  26. <Rectangle Fill="{x:Null}" Name="OpaqueRect" Width="Auto" Height="Auto" />
  27. </Canvas>
  28. <Rectangle Fill="{DynamicResource Menu.Margin.Background}" Width="24" HorizontalAlignment="Left" />
  29. <ItemsPresenter Name="ItemsPresenter" Margin="0,1,0,1" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Cycle" />
  30. </Grid>
  31. </ScrollViewer>
  32. </Border>
  33. </StackPanel>
  34. </mwt:SystemDropShadowChrome>
  35. <ControlTemplate.Triggers>
  36. <Trigger Property="ContextMenuService.HasDropShadow">
  37. <Setter Property="FrameworkElement.Margin" TargetName="Shdw">
  38. <Setter.Value>
  39. <Thickness>0,0,5,5</Thickness>
  40. </Setter.Value>
  41. </Setter>
  42. <Setter Property="mwt:SystemDropShadowChrome.Color" TargetName="Shdw">
  43. <Setter.Value>
  44. <Color>#71000000</Color>
  45. </Setter.Value>
  46. </Setter>
  47. <Trigger.Value>
  48. <s:Boolean>True</s:Boolean>
  49. </Trigger.Value>
  50. </Trigger>
  51. <Trigger Property="ScrollViewer.CanContentScroll" SourceName="ContextMenuScrollViewer">
  52. <Setter Property="Canvas.Top" TargetName="OpaqueRect">
  53. <Setter.Value>
  54. <Binding Path="VerticalOffset" ElementName="ContextMenuScrollViewer" />
  55. </Setter.Value>
  56. </Setter>
  57. <Setter Property="Canvas.Left" TargetName="OpaqueRect">
  58. <Setter.Value>
  59. <Binding Path="HorizontalOffset" ElementName="ContextMenuScrollViewer" />
  60. </Setter.Value>
  61. </Setter>
  62. <Trigger.Value>
  63. <s:Boolean>False</s:Boolean>
  64. </Trigger.Value>
  65. </Trigger>
  66. <Trigger Property="HasItems" SourceName="ToolBar" Value="True">
  67. <Setter Property="Visibility" TargetName="ToolBarBorder" Value="Visible"/>
  68. </Trigger>
  69. </ControlTemplate.Triggers>
  70. </ControlTemplate>
  71. </Setter.Value>
  72. </Setter>
  73. </Style>
  74. </ContextMenu.Resources>
  75. </ContextMenu>