Articles in this section
Category / Section

How to add ContextMenu for WPF Chart?

1 min read

ContextMenu can be added for WPF SfChart elements by setting ContextMenu with required MenuItem collection for SfChart. By raising the required events of MenuItem, you can customize the SfChart.

Similarly, you can also enable ContextMenu for other chart elements by raising the required events of MenuItem. You can check this implementation in this sample.

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

Chart with zooming ContextMenu

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