We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add custom menu items to EditControl Embedded ContextMenu?


EditControl has default embedded ContextMenu. This ContextMenu also supports to add the custom ContextMenuItem. Here we have added the custom context menu item, following code demonstrates the same.

 

Code Example: [Xaml]

 

<Window.Resources>
 
<ContextMenu x:Key="contextmenu">
 
<MenuItem Header="Undo" Command="{x:Static syncfusion:EditCommands.Undo}" 
 
CommandTarget="{Binding RelativeSource={RelativeSource AncestorType={x:Type 
 
syncfusion:EditControl}}}">
 
<MenuItem.Icon>
 
<Image Source="pack://application:,,,/Syncfusion.Edit.Wpf;component/Resources/Undo.png" />
 
</MenuItem.Icon>
 
</MenuItem>
 
<MenuItem Header="Redo" Command="{x:Static syncfusion:EditCommands.Redo}" CommandTarget="{Binding 
 
RelativeSource={RelativeSource AncestorType={x:Type syncfusion:EditControl}}}">
 
<MenuItem.Icon>
 
<Image Source="pack://application:,,,/Syncfusion.Edit.Wpf;component/Resources/Redo.png" />
 
</MenuItem.Icon>
 
</MenuItem>
 
<MenuItem  Header="Cut" Command="{x:Static syncfusion:EditCommands.Cut}" CommandTarget="{Binding 
 
RelativeSource={RelativeSource AncestorType={x:Type syncfusion:EditControl}}}">
 
<MenuItem.Icon>
 
<Image Source="pack://application:,,,/Syncfusion.Edit.Wpf;component/Resources/Cut.png" />
 
</MenuItem.Icon>
 
</MenuItem>
 
<MenuItem Header="Copy" Command="{x:Static syncfusion:EditCommands.Copy}" CommandTarget="{Binding 
 
RelativeSource={RelativeSource AncestorType={x:Type syncfusion:EditControl}}}">
 
<MenuItem.Icon>
 
<Image Source="pack://application:,,,/Syncfusion.Edit.Wpf;component/Resources/Copy.png" />
 
</MenuItem.Icon>
 
</MenuItem>
 
<MenuItem Header="Paste" Command="{x:Static syncfusion:EditCommands.Paste}" CommandTarget="{Binding 
 
RelativeSource={RelativeSource AncestorType={x:Type syncfusion:EditControl}}}">
 
<MenuItem.Icon>
 
<Image Source="pack://application:,,,/Syncfusion.Edit.Wpf;component/Resources/Paste.png" />
 
</MenuItem.Icon>
 
</MenuItem>
 
<MenuItem Header="SelectAll" Command="{x:Static syncfusion:EditCommands.SelectAll}" 
 
CommandTarget="{Binding RelativeSource={RelativeSource AncestorType={x:Type 
 
syncfusion:EditControl}}}">
 
</MenuItem>
 
<MenuItem Header="Outlining">
 
<MenuItem Header="ExpandallText}" Command="{x:Static syncfusion:EditCommands.ExpandAll}" 
 
CommandTarget="{Binding RelativeSource={RelativeSource AncestorType={x:Type 
 
syncfusion:EditControl}}}">
 
</MenuItem>
 
<MenuItem Header="Collapseall" Command="{x:Static syncfusion:EditCommands.CollapseAll}" 
 
CommandTarget="{Binding RelativeSource={RelativeSource AncestorType={x:Type 
 
syncfusion:EditControl}}}">
 
</MenuItem>
 
</MenuItem>
 
<!-- Add Custom Context Menu -->
 
<MenuItem Header="Go To Definition"/>
 
<MenuItem Header="Find All References"/>
 
<MenuItem Header="Break Point"/>
 
<MenuItem Header="View Hierarchy"/>
 
<MenuItem Header="Increaseindent" Command="{x:Static syncfusion:EditCommands.IncreaseIndent}" 
 
CommandTarget="{Binding RelativeSource={RelativeSource AncestorType={x:Type 
 
syncfusion:EditControl}}}">
 
<MenuItem.Icon>
 
<Image Source="pack://application:,,,/Syncfusion.Edit.Wpf;component/Resources/IncreaseIndent.png" />
 
</MenuItem.Icon>
 
</MenuItem>
 
<MenuItem Header="Decreaseindent" Command="{x:Static syncfusion:EditCommands.DecreaseIndent}" 
 
 
CommandTarget="{Binding RelativeSource={RelativeSource AncestorType={x:Type 
 
syncfusion:EditControl}}}">
 
<MenuItem.Icon>
 
<Image Source="pack://application:,,,/Syncfusion.Edit.Wpf;component/Resources/DecreaseIndent.png" />
 
</MenuItem.Icon>
 
</MenuItem>
 
<MenuItem Header="Commentlines" Command="{x:Static syncfusion:EditCommands.CommentSelection}" 
 
CommandTarget="{Binding RelativeSource={RelativeSource AncestorType={x:Type 
 
syncfusion:EditControl}}}">
 
<MenuItem.Icon>
 
<Image Source="pack://application:,,,/Syncfusion.Edit.Wpf;component/Resources/Comment.png" 
MaxHeight="16" MaxWidth="16" />
 
</MenuItem.Icon>
 
</MenuItem>
 
<MenuItem Header="Uncommentlines" Command="{x:Static syncfusion:EditCommands.UncommentSelection}" 
 
CommandTarget="{Binding RelativeSource={RelativeSource AncestorType={x:Type 
 
syncfusion:EditControl}}}">
 
<MenuItem.Icon>
 
<Image Source="pack://application:,,,/Syncfusion.Edit.Wpf;component/Resources/Uncomment.png" 
MaxHeight="16" MaxWidth="16" />
 
</MenuItem.Icon>
 
</MenuItem>
 
</ContextMenu>
 
</Window.Resources>
 
<!-- EditControl -->
 
<syncfusion:EditControl ContextMenu="{StaticResource contextmenu}" Name="editText" 
 
Background="White" BorderBrush="Black" FontFamily="Verdana" FontSize="14" Foreground="Black" 
 
IsReadOnly="False" 
 
ShowDefaultContextMenu="False" >
          
</syncfusion:EditControl>

 

Screenshot

 

Default ContextMenu.

Figure: Default ContextMenu.

 

After Adding Custom ContextMenuItem

Figure: After Adding Custom ContextMenuItem.

 

Sample

 

C#:  EditControlSample

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile