Pre loader

ContextMenu does not work on graph when panning is enabled by right mouse button.

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

1
0

Hi Scichart,

I am struggling with a ContextMenu on a SciChartSurface that wont be displayed.

The problem started when i added mouse panning with the right mouse-button which is the same button the ContextMenu is activated on.

So will this combination even work – with both a ContextMenu and mouse panning with the right mouse button?

To manually validate if the ContextMenu should open or if the panning should be enabled, I have tried to get the mouse coordinates manually in C# to see if the mouse was moved(panning) or if it was a click(ContextMenu). This did not work very well when i afterwards started to pan/zoom again.

Do you have a code example using both a ContextMenu and mouse panning using right mouse button?

Best regards,
Jeppe

  • You must to post comments
2
0

Update: SciChart v4

We have a working solution with SciChart v4 below. What we have done is implemented showing the context menu on SciChartSurface.PreviewMouseUp event.

We have also overridden ZoomPanModifier to ensure that e.Handled is only ever true when panning (e.g. if Start / End Point are not the same).

Here’s the code:

MainWindow.xaml

<Window x:Class="WpfApplication85.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
        xmlns:wpfApplication85="clr-namespace:WpfApplication85"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <s:SciChartSurface Name="sciChart" PreviewMouseUp="SciChart_OnPreviewMouseUp">
            <s:SciChartSurface.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Item1" />
                    <MenuItem Header="Item2" />
                </ContextMenu>
            </s:SciChartSurface.ContextMenu>

            <s:SciChartSurface.XAxis>
                <s:NumericAxis/>
            </s:SciChartSurface.XAxis>

            <s:SciChartSurface.YAxis>
                <s:NumericAxis/>
            </s:SciChartSurface.YAxis>

            <s:SciChartSurface.ChartModifier>
                <s:ModifierGroup>
                    <wpfApplication85:ZoomPanModifierEx ExecuteOn="MouseRightButton" ClipModeX="None"></wpfApplication85:ZoomPanModifierEx>                    
                    <s:CursorModifier ReceiveHandledEvents="True" />
                </s:ModifierGroup>
            </s:SciChartSurface.ChartModifier>
        </s:SciChartSurface>
    </Grid>
</Window>

MainWindow.xaml.cs

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void SciChart_OnPreviewMouseUp(object sender, MouseButtonEventArgs e)
    {
        if (e.RightButton == MouseButtonState.Pressed)
        {
            ((SciChartSurface)sender).ContextMenu.IsOpen = true;
            e.Handled = true;
        }
    }
}  

ZoomPanModifierEx.cs

public class ZoomPanModifierEx : ZoomPanModifier
{
    private Point _startPoint;

    public override void OnModifierMouseDown(ModifierMouseArgs e)
    {
        base.OnModifierMouseDown(e);

        _startPoint = e.MousePoint;
    }

    public override void OnModifierMouseUp(ModifierMouseArgs e)
    {
        base.OnModifierMouseUp(e);

        if (_startPoint == e.MousePoint) e.Handled = false;
    }
}

Best regards,
Andrew

  • Andrew Burnett-Thompson
    EDIT: You don’t actually need the explicit PreviewMouseUp event either. It works without it. The important point is to ensure that MouseUp is not handled in modifiers if you don’t complete a pan operation.
  • kurtisnet
    This works perfectly! Thank you Andrew for the code. :)
  • You must to post comments
0
0

I am considering applying server-side licensing for my javerScript application.

In the document below, there is a phrase “Our server-side licensing component is written in C++.”
(https://support.scichart.com/index.php?/Knowledgebase/Article/View/17256/42/)

However, there is only asp.net sample code on the provided github.
(https://github.com/ABTSoftware/SciChart.JS.Examples/tree/master/Sandbox/demo-dotnet-server-licensing)

I wonder if there is a sample code implemented in C++ for server-side licensing.

Can you provide c++ sample code?
Also, are there any examples to run on Ubuntu?

  • You must to post comments
0
0

Hi Jeppe,

This is because the ZoomPanModifier menu sets e.Handled = true on the mouse event when it handles a pan, which will stop WPF raising the event to other parts of your UI (such as Context Menu).

There is no simple fix for this. If you were to override ZoomPanModifier.OnModifierMouseDown and set e.Handled = true, the pan would work, but the context menu would show as well (e.g. you would get a floating menu while the chart is panning).

Your best bet is to create a custom pan modifier based off our tutorial Custom ChartModifiers – Part 2 – Custom ZoomPanModifier and Zooming on KeyPress and use this modifier to handle both showing of context menu and panning.

Best regards,
Andrew

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies