Вы можете добавить заголовок к ControlTemplate ContextMenu. Вы можете получить ControlTemplate по умолчанию для ContextMenu, используя решение здесь , а затем изменить его, добавив заголовок. Я сделал это ниже:
<UserControl.ContextMenu>
<ContextMenu>
<ContextMenu.Template>
<ControlTemplate TargetType="ContextMenu" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
<mwt:SystemDropShadowChrome Color="#00FFFFFF" Name="Shdw" SnapsToDevicePixels="True">
<Border BorderThickness="{TemplateBinding Border.BorderThickness}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" Name="ContextMenuBorder">
<ScrollViewer Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly=FrameworkElement, ResourceId=MenuScrollViewer}}" Name="ContextMenuScrollViewer" Margin="1,0,1,0" Grid.ColumnSpan="2">
<StackPanel>
<Label>Your title goes here</Label>
<Grid RenderOptions.ClearTypeHint="Enabled">
<Canvas Width="0" Height="0" HorizontalAlignment="Left" VerticalAlignment="Top">
<Rectangle Fill="{x:Null}" Name="OpaqueRect" Width="Auto" Height="Auto" />
</Canvas>
<Rectangle RadiusX="2" RadiusY="2" Fill="#FFF1F1F1" Width="28" Margin="1,2,1,2" HorizontalAlignment="Left" />
<Rectangle Fill="#FFE2E3E3" Width="1" Margin="29,2,0,2" HorizontalAlignment="Left" />
<Rectangle Fill="#FFFFFFFF" Width="1" Margin="30,2,0,2" HorizontalAlignment="Left" />
<ItemsPresenter Name="ItemsPresenter" Margin="{TemplateBinding Control.Padding}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Cycle" />
</Grid>
</StackPanel>
</ScrollViewer>
</Border>
</mwt:SystemDropShadowChrome>
<ControlTemplate.Triggers>
<Trigger Property="ContextMenuService.HasDropShadow">
<Setter Property="FrameworkElement.Margin" TargetName="Shdw">
<Setter.Value>
<Thickness>0,0,5,5</Thickness>
</Setter.Value>
</Setter>
<Setter Property="mwt:SystemDropShadowChrome.Color" TargetName="Shdw">
<Setter.Value>
<Color>#71000000</Color>
</Setter.Value>
</Setter>
<Trigger.Value>
<s:Boolean>True</s:Boolean>
</Trigger.Value>
</Trigger>
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="ContextMenuScrollViewer">
<Setter Property="Canvas.Top" TargetName="OpaqueRect">
<Setter.Value>
<Binding Path="VerticalOffset" ElementName="ContextMenuScrollViewer" />
</Setter.Value>
</Setter>
<Setter Property="Canvas.Left" TargetName="OpaqueRect">
<Setter.Value>
<Binding Path="HorizontalOffset" ElementName="ContextMenuScrollViewer" />
</Setter.Value>
</Setter>
<Trigger.Value>
<s:Boolean>False</s:Boolean>
</Trigger.Value>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ContextMenu.Template>
<MenuItem Header="Start" IsEnabled="{Binding ControlPanelViewModel.IsStartEnabled}" Command="{Binding Path=ControlPanelViewModel.StartEscalatorCommand}"/>
<MenuItem Header="Stop" IsEnabled="{Binding ControlPanelViewModel.IsStopEnabled}" Command="{Binding Path=ControlPanelViewModel.StopEscalatorCommand}"/>
<Separator/>
<MenuItem x:Name="OpenControl" Header="Control panel..." Command="{Binding OpenControlPanelCommand}">
<MenuItem.Icon>
<Path Data="M19,4C20.11,4 21,4.9 21,6V18A2,2 0 0,1 19,20H5C3.89,20 3,19.1 3,18V6A2,2 0 0,1 5,4H19M19,18V8H5V18H19Z" Fill="Black" Margin="-5"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</UserControl.ContextMenu>
Ключевой модификацией было обернуть Grid
в StackPanel
и добавить Label
с заголовком над Grid
. Поскольку в ControlTemplate по умолчанию используется Aero, вам необходимо сослаться на PresentationFramework.Aero в вашем проекте.