Pre loader

Events in MVVM

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

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.

Try SciChart Today

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

Start TrialCase Studies