SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components



It is me again….

As I have said before, our application is using MVVM and WPF (C#) and I am wondering if you guys have an example or if you could give me some suggestion of how to implement a menu when ALT-right-click on the chart, like in the picture attached?

Hope you can help me…

Thanks very much.. 🙂

  • You must to post comments

Hi there,

Unfortunately, we don’t have such an example, but lots of SciChart customers have implemented this behavior for their apps, so I think there shouldn’t be any complications. There is an example how to do this using custom modifier:

        <s:SciChartSurface Name="sciChart"
                <ContextMenu IsOpen="{Binding IsOpen, Mode=OneWay, ElementName=ContextMenuModifier}">
                    <MenuItem Header="Item1" />
                    <MenuItem Header="Item2" />


                    <CreateSimpleChart:ContextMenuModifier x:Name="ContextMenuModifier" ReceiveHandledEvents="True" />
                    <s:CursorModifier ReceiveHandledEvents="True" />

..and modifier’s code:

    public class ContextMenuModifier: ChartModifierBase
        public static readonly DependencyProperty IsOpenProperty =
            DependencyProperty.Register("IsOpen", typeof(bool), typeof(ContextMenuModifier), new PropertyMetadata(false));

        public bool IsOpen
            get { return (bool)GetValue(IsOpenProperty); }
            set { SetValue(IsOpenProperty, value); }

        public override void OnAttached()

            // Subscribe to listen to ContextMenuOpening event on ParentSurface
            (ParentSurface as SciChartSurface).ContextMenuOpening += OnSurfaceContextMenuOpening;

        private void OnSurfaceContextMenuOpening(object sender, ContextMenuEventArgs e)
            // If !IsOpen, prevent menu from being show by handling the event
            e.Handled = !IsOpen;

        public override void OnModifierMouseDown(ModifierMouseArgs e)
            IsOpen = false;

        public override void OnModifierMouseUp(ModifierMouseArgs e)
            // Open menu if right mouse btn was clicked and Alt btn was pressed
            // IsOpen should be OneWay-bound to SciChartSurface.ContextMenu.IsOpen
            IsOpen = (e.MouseButtons == MouseButtons.Right) && (e.Modifier == MouseModifier.Alt);

I think the above give you an idea how to implement similar behavior. Please, notice, that you need to release Alt button quickly, because the ContextMenu will disappear just after being shown(strange issue).

Also there are a few threads connected to this issue, you can find some useful info or another ideas there: ContextMenu for chart series and Keyboard shortcuts to pan.

Hope this helps!

Best regards,

  • vaquita50
    Thanks Yuriy... This is a great start.... I will try to implement it and if I have any problem I may bother you again. Have a nice weekend!! :)
  • Andrew Burnett-Thompson
    I must say this is good stuff - might make a good example (or tutorial). Thanks Yuriy!
  • You must to post comments

I am using this code example but have trouble connecting the MenuItems to a command.

I am using MVVM Light and created a RelayCommand on ContextMenuModifier and used the same name in Command, but the attached subroutine never fires ( as in other parts of my code). How and to where do I bind the Command of a ContextMenuItem as in this example.

New to WPF. Love the binding, but hate the debugging to see to what it is actually bound too 🙁

  • Andrew Burnett-Thompson
    I think you need to check the DataContext property of the menu that is shown. Any commands in a ViewModel must be bound to MenuItems, the MenuItem needs to have the DataContext set to the instance of the view model. If it's not, then you can wire it up yourself, e.g. by setting Menu.DataContext = ChartModifierBase.DataContext (assuming, that the data context of your chart modifier base is in fact the correct view model). PS Finally, WPF Snoop (free from codeplex) can help you debug MVVM bindings and show binding errors. Best regards, Andrew
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.