Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The idea is to override default <code>ContextMenu</code> template.</p> <p>Result:</p> <p><img src="https://i.stack.imgur.com/4EpSF.png" alt="enter image description here"></p> <p>Add reference to <code>PresentationFramework.Aero.dll</code> and try this code:</p> <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" Title="MainWindow" Height="350" Width="525"&gt; &lt;Window.Resources&gt; &lt;Style x:Key="MenuStyle" TargetType="{x:Type ContextMenu}" BasedOn="{StaticResource {x:Type ContextMenu}}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type ContextMenu}"&gt; &lt;StackPanel&gt; &lt;theme:SystemDropShadowChrome Name="Shdw2" Color="Transparent" SnapsToDevicePixels="true"&gt; &lt;Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBox Text="{Binding ShiftValue, UpdateSourceTrigger=PropertyChanged}" Width="30" Margin="4"&gt; &lt;TextBox.InputBindings&gt; &lt;KeyBinding Command="{Binding ShiftCommand}" Key="Enter" /&gt; &lt;/TextBox.InputBindings&gt; &lt;/TextBox&gt; &lt;Button Content="Shift" Margin="0,4,0,4" Command="{Binding ShiftCommand}" /&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;/theme:SystemDropShadowChrome&gt; &lt;theme:SystemDropShadowChrome Name="Shdw" Color="Transparent" SnapsToDevicePixels="true"&gt; &lt;Border Name="ContextMenuBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"&gt; &lt;Grid&gt; &lt;Rectangle Fill="#F1F1F1" HorizontalAlignment="Left" Width="28" Margin="2" RadiusX="2" RadiusY="2" /&gt; &lt;Rectangle HorizontalAlignment="Left" Width="1" Margin="30,2,0,2" Fill="#E2E3E3" /&gt; &lt;Rectangle HorizontalAlignment="Left" Width="1" Margin="31,2,0,2" Fill="White" /&gt; &lt;ScrollViewer Name="ContextMenuScrollViewer" CanContentScroll="true" Grid.ColumnSpan="2" Margin="1,0" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type FrameworkElement}, ResourceId=MenuScrollViewer}}"&gt; &lt;Grid RenderOptions.ClearTypeHint="Enabled"&gt; &lt;Canvas Height="0" Width="0" HorizontalAlignment="Left" VerticalAlignment="Top"&gt; &lt;Rectangle Height="{Binding ElementName=ContextMenuBorder,Path=ActualHeight}" Width="{Binding ElementName=ContextMenuBorder,Path=ActualWidth}" Fill="{Binding ElementName=ContextMenuBorder,Path=Background}" /&gt; &lt;/Canvas&gt; &lt;ItemsPresenter Name="ItemsPresenter" Margin="{TemplateBinding Padding}" KeyboardNavigation.DirectionalNavigation="Cycle" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /&gt; &lt;/Grid&gt; &lt;/ScrollViewer&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/theme:SystemDropShadowChrome&gt; &lt;/StackPanel&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="HasDropShadow" Value="true"&gt; &lt;Setter TargetName="Shdw" Property="Margin" Value="0,0,5,5" /&gt; &lt;Setter TargetName="Shdw" Property="Color" Value="#71000000" /&gt; &lt;Setter TargetName="Shdw2" Property="Margin" Value="0,0,5,5" /&gt; &lt;Setter TargetName="Shdw2" Property="Color" Value="#71000000" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;DataGrid IsReadOnly="True"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Binding="{Binding}" /&gt; &lt;/DataGrid.Columns&gt; &lt;DataGrid.ContextMenu&gt; &lt;ContextMenu Style="{StaticResource MenuStyle}"&gt; &lt;MenuItem Header="Item 1"&gt;&lt;/MenuItem&gt; &lt;MenuItem Header="Item 2"&gt;&lt;/MenuItem&gt; &lt;MenuItem Header="Item 3"&gt;&lt;/MenuItem&gt; &lt;/ContextMenu&gt; &lt;/DataGrid.ContextMenu&gt; &lt;System:String&gt;One&lt;/System:String&gt; &lt;System:String&gt;Two&lt;/System:String&gt; &lt;System:String&gt;Three&lt;/System:String&gt; &lt;/DataGrid&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload