Pre loader

MVVM and SelectedPointMarkers - struggling to access Coordinates of selected point inside ViewModel

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

0
0

Hi,

I am developing an MVVM WPF application and need to access the SelectedPointMarkers property of DataPointSelectionModifier from the ViewModel.

From looking at the DataPointSelectionModifier documentation (https://www.scichart.com/documentation/win/current/webframe.html#DataPoint%20Selection.html) I can see how you can get the X and Y coordinate values of a selected point in a view, by binding the PointMarkersSelectionModifier to a listbox.

However this doesn’t really help me, I need to get the coordinates of the SelectedPointMarker into a property inside the ViewModel that can be accessed, rather than just binding to a listbox in the view itself.

I’ve also looked at this similar post: (https://www.scichart.com/questions/wpf/i-want-to-bind-selectedpointmarkers-of-datapointselectionmodifier), but I had no luck getting Kenishis solution to work in my case.

How can i do this?

Thanks.

Version
6.4.0.13629
  • You must to post comments
0
0

Hi Sean,

It’s possible to solve by inheriting the DataPointSelectionModifier and creating your own dependency property for SelectedPointMarkers

public class DataPointSelectionModifierExtended : DataPointSelectionModifier
{
    public static readonly DependencyProperty AllSelectedPointMarkersProperty = DependencyProperty.Register
        (nameof(AllSelectedPointMarkers),
        typeof(ObservableCollection<DataPointInfo>),
        typeof(DataPointSelectionModifierExtended),
        new PropertyMetadata(new ObservableCollection<DataPointInfo>()));

    public ObservableCollection<DataPointInfo> AllSelectedPointMarkers
    {
        get => (ObservableCollection<DataPointInfo>)GetValue(AllSelectedPointMarkersProperty);
        set => SetValue(AllSelectedPointMarkersProperty, value);
    }

    public DataPointSelectionModifierExtended()
    {
        SelectedPointMarkers.CollectionChanged += OnCollectionChanged;
    }

    private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        switch (e.Action)
        {
            case NotifyCollectionChangedAction.Add:
                e.NewItems.Cast<DataPointInfo>().ForEachDo(p => AllSelectedPointMarkers.Add(p));
                break;

            case NotifyCollectionChangedAction.Reset:
                AllSelectedPointMarkers.Clear();
                break;

            case NotifyCollectionChangedAction.Remove:
                e.OldItems.Cast<DataPointInfo>().ForEachDo(p => AllSelectedPointMarkers.Remove(p));
                break;

            case NotifyCollectionChangedAction.Replace:
            case NotifyCollectionChangedAction.Move:
            default: throw new NotImplementedException();
        }
    }
}

Best regards,
Dmytro

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.