How to add ContextMenu for WPF Chart?
ContextMenu can be added to WPF SfChart elements by setting a ContextMenu with the required MenuItem collection for the SfChart. By raising the required events of the MenuItem, you can customize the SfChart. Similarly, you can also enable a ContextMenu for other chart elements by raising the required events of the MenuItem.
XAML
<chart:SfChart x:Name="Chart" Margin="10" Background="White"> … <chart:SfChart.ContextMenu> <ContextMenu> <MenuItem Header="Zooming"> <MenuItem Header="EnableZooming" Click="ChartZoomItem_Click"/> <MenuItem Header="DisableZooming" Click="ChartZoomItem_Click"/> </MenuItem> </ContextMenu> </chart:SfChart.ContextMenu> </chart:SfChart>
C#
public partial class MainWindow : Window { private ChartZoomPanBehavior zoomPanBehavior = new ChartZoomPanBehavior()
{
EnableZoomingToolBar = true,
EnableSelectionZooming = true
}; … // Method to enable and disable zooming for SfChart. private void ChartZoomItem_Click(object sender, RoutedEventArgs e) { … } }
Output
Conclusion
I hope you enjoyed learning how to add ContextMenu for WPF Chart.
You can refer to our WPF Chart feature tour page know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Chart Examples 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!