Articles in this section
Category / Section

How to display separator in custom contextmenu of WPF DockingManager?

1 min read

As per current implementation of WPF DockingManager CustomContextMenu there is no direct support to add separator as like in Menu control. But this can be achieved by customizing the MenuItem style of the CustomContextMenu with help of IsSeparator property of SeparatorExt class. If the attached property "IsSeparator" is true, separator will be displayed instead of header. Below code snippets are demonstrate the same,

DockWindowMenuItemStyle:

<Style TargetType="MenuItem" x:Key="DockWindowMenuItemSeparatorStyle">
  <Style.Triggers>
    <Trigger Property="local:SeparatorExt.IsSeparator" Value="True">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate>
            <Border Height="1" Margin="5,0,5,0" BorderBrush="#FFD7D7D7" BorderThickness="0.5"/>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Trigger>
  </Style.Triggers>
</Style>

DocumentWindowMenuItemStyle:

<Style TargetType="MenuItem" x:Key="DocumentMenuItemSeparatorStyle">
  <Style.Triggers>
    <Trigger Property="local:SeparatorExt.IsSeparator" Value="True">
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate>
            <Border Height="1" Margin="26,0,5,0" BorderBrush="#FFD7D7D7" BorderThickness="0.5"/>
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Trigger>
  </Style.Triggers>
</Style>

MainWindow.xaml

<syncfusion:DockingManager DockWindowContextMenuItemStyle="{StaticResource DockWindowMenuItemSeparatorStyle}" UseDocumentContainer="True" Name="Docking" >
  <syncfusion:DockingManager.DocumentTabItemStyle>
    <Style TargetType="syncfusion:TabItemExt">
      <Setter Property="TabItemContextMenuItemStyle" Value="{StaticResource DocumentMenuItemSeparatorStyle}"/>
    </Style>
  </syncfusion:DockingManager.DocumentTabItemStyle>
            
  <syncfusion:DockingManager.DocumentTabItemContextMenuItems>
    <syncfusion:DocumentTabItemMenuItemCollection>
      <syncfusion:CustomMenuItem Header="Custom1" />
      <syncfusion:CustomMenuItem Header="Custom2" local:SeparatorExt.IsSeparator="True"/>
      <syncfusion:CustomMenuItem Header="Custom3" />
    </syncfusion:DocumentTabItemMenuItemCollection>
  </syncfusion:DockingManager.DocumentTabItemContextMenuItems>
            
  <syncfusion:DockingManager.CustomMenuItems>
    <syncfusion:CustomMenuItemCollection>
      <syncfusion:CustomMenuItem Header="Custom1"/>
      <syncfusion:CustomMenuItem Header="Custom2"/>
      <syncfusion:CustomMenuItem Header="Custom3"/>
      <syncfusion:CustomMenuItem local:SeparatorExt.IsSeparator="True"/>
      <syncfusion:CustomMenuItem Header="Custom4"/>
    </syncfusion:CustomMenuItemCollection>
  </syncfusion:DockingManager.CustomMenuItems>
            
  <ContentControl x:Name="Dock1" syncfusion:DockingManager.Header="Dock1" syncfusion:DockingManager.DesiredWidthInDockedMode="300"/>
  <ContentControl syncfusion:DockingManager.Header="Dock2" syncfusion:DockingManager.SideInDockedMode="Tabbed" syncfusion:DockingManager.TargetNameInDockedMode="Dock1"/>
  <ContentControl syncfusion:DockingManager.Header="Dock3" syncfusion:DockingManager.State="Document"/>
  <ContentControl syncfusion:DockingManager.Header="Dock4" syncfusion:DockingManager.State="Document"/>
</syncfusion:DockingManager>         

SeparatorExt.cs

public class SeparatorExt : DependencyObject
{
  public static bool GetIsSeparator(DependencyObject obj)
  {
    return (bool)obj.GetValue(IsSeparatorProperty);
  }
 
  public static void SetIsSeparator(DependencyObject obj, bool value)
  {
    obj.SetValue(IsSeparatorProperty, value);
  }
 
  // Using a DependencyProperty as the backing store for IsSeparator.  This enables animation, styling, binding, etc...
  public static readonly DependencyProperty IsSeparatorProperty = DependencyProperty.RegisterAttached("IsSeparator", typeof(bool), typeof(SeparatorExt), new PropertyMetadata(false));
}

 

WPF DockingManager displays custom contextmenu

 

Conclusion

I hope you enjoyed learning about how to display separator in custom contextmenu of WPF DockingManager.

You can refer to our  WPF DockingManager feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF DockingManage documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied