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

Right Click context menu separator

How do you add a menu separator to a Syncfusion chart right click context menu?

This is a dynamic menu and can't be done directly in XAML.

We're using Syncfusion.Chart.WPF.DLL version 9.203.0.137 in a .net 4.0 WPF desktop application.

Here is a simplified version of our code to create the chart and right click menu.

Chart g = new SyncFusion.Windows.Chart.Chart();

..setup other chart properties

ChartArea chartArea = new ChartArea();

..setup other chart area properties

chartArea.IsContextMenuEnabled = true;
chartArea.ContextMenuType = ContextMenuTypes.Custom;

//add menu items to right click context menu

MenuItem m = new MenuItem();
m.Header = "Show test dialog";
m.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(ShowTextDialog_OnClick);
chartArea.CustomContextMenuItems.Add(m);

//separator should go here

MenuItem m2 = new MenuItem();
m2.Header = "Show test dialog2";
m2.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(ShowTextDialog2_OnClick);
chartArea.CustomContextMenuItems.Add(m2);

g.Areas.Add(chartArea);




1 Reply

GA Ganesan Syncfusion Team November 7, 2011 02:50 AM UTC

Hi George,


We have analyzed your requirement, and there is no special support for adding a separator to the context menu. But your requirement can be achieved by overriding the datatemplate of contextmenuitem header as in below code snippet.


Code Snippet [Xaml]:







Code Snippet [C#]:

area.IsContextMenuEnabled = true;

area.ContextMenuType = ContextMenuTypes.Custom;

ContextMenu menu = new ContextMenu();

MenuItem seperator = new MenuItem();

seperator.Height = 7;

seperator.Width = 200;

seperator.VerticalContentAlignment = System.Windows.VerticalAlignment.Stretch;

seperator.HeaderTemplate = this.Resources["Seperator"] as DataTemplate;

seperator.Header = "Seperator Header";

menu.Items.Add("Rotate Series");

menu.Items.Add("Zomming");

menu.Items.Add(seperator);

menu.Items.Add("Print");

menu.Items.Add("Save");

area.ContextMenu = menu;


Based on your requirement we have created a simple sample, which you can download from the link below.


http://www.syncfusion.com/downloads/Support/DirectTrac/86851/WPFChartCase1011509621.zip


Please let us know if you have any concerns.


Thanks,

Ganesan




Loader.
Live Chat Icon For mobile
Up arrow icon