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

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

Answered
0
0

Hi,

How can I capture an event (mouse event or something like that) in my ViewModel after zooming or panning the chart.

Thanks,
Egbert

  • You must to post comments
Best Answer
1
0

Hi again,

Please, take a look on this example:

                <SciChart:NumericAxis AxisTitle="Time (ms)"
                                      TextFormatting="0.00"
                                      VisibleRange="{Binding XVisibleRange,
                                                             Mode=TwoWay}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="VisibleRangeChanged">
                            <local:ExecuteCommandAction Command="{Binding OnVisibleRangeChanged}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </SciChart:NumericAxis>

ExecuteCommandAction class:

    public class ExecuteCommandAction : TriggerAction<Control>
    {
        public static readonly DependencyProperty CommandProperty =
            DependencyProperty.Register("Command", typeof(ICommand), typeof(ExecuteCommandAction), new PropertyMetadata(null));

        public ICommand Command
        {
            get { return (ICommand)GetValue(CommandProperty); }
            set { SetValue(CommandProperty, value); }
        }

        protected override void Invoke(object parameter)
        {
            if(Command != null && Command.CanExecute(null))
            {
                Command.Execute(null);
            }
        }
    }

Could you try out this approach and give us a feedback if this is what you want?

Yuriy

  • EJansen
    Hi,Thanks, it works great now. Your first answer already gave me the solution.We are using the following xaml code:
                    <SciChart:SciChartSurface Grid.Column="0" Grid.Row="0" x:Name="sciChartSurface" 
                                          DataSet="{Binding ChartData, Mode=TwoWay}"
                                          RenderableSeries="{Binding RenderableSeries}"
                                          SciChart:ThemeManager.Theme="{Binding SciChartTheme}"
                                          XAxis="{Binding XAxis}" 
                                          YAxes="{Binding YAxes}"
                                          Annotations="{Binding Annotations}"
                                          ChartModifier="{Binding ChartModifier}" >
                    </SciChart:SciChartSurface>
    In the ViewModel we are using:this.XAxis.VisibleRangeChanged += new EventHandler(VisibleRangeChangedEvent); and the same for the Yaxes
  • You must to post comments
0
0

Hi there,

When you zoom or pan a chart, VisibleRange changed and VisibleRangeChanged event fired on axes. So you could bind this event to command in your ViewModel using EventTriggers and InvokeCommandAction.

Please, feel free to ask if you have any questions!

Best regards,
Yuriy

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.