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!

0
0

Hello,

Is there a mechanism for binding, in a two way fashion, the collection of Selected points when using the IPointmetadata mechnism?

Basically, I have a view which contains a table (DevExpress Datagrid) and a SciChart plot, where all of the rows are plotted on a line series. When the user highlights a row or rows in the table, the appropriate points should be selected on the graph. Also, if the user selects the points on the graph, the rows should be selected in the table. Ideally, I would like to bind each view’s SelectedRows (or SelectedPoints) to a common ObservableCollection.

The trouble I am seeing is that the two views use different paradigms to represent Selected-ness. The point is only selectable if it is given an object that implements IPointMetadata, and its selection state is represented by the BizObjectViewModel’s IsSelected property. The selection state in the table is represented by its presence in the SelectedRows collection.

No opinions as to which is better, I am simply trying to get the two to work together nicely. OnCollectionChanged of the bound SelectedRows is a great place for me to set/unset IsSelected for the affected object, and the chart reacts:

switch (e.Action)
        {
            case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                foreach (var p in e.NewItems.Cast<SolverDetailRow>())
                {
                    p.IsSelected = true;
                }
                break;
            case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                foreach (var p in e.OldItems.Cast<SolverDetailRow>())
                {
                    p.IsSelected = false;
                }
                break;
            case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                break;
            case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
                break;
            case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                foreach (var row in SolverRows)
                {
                    foreach (var detRow in row.Observations)
                    {
                        detRow.IsSelected = false;
                    }
                }
                break;
            default:
                break;
        }

However, I can’t find the best place to update the collection when the chart updates the IsSelected property itself. The BizObjectViewModel won’t (and shouldn’t) know about the collection he is in. Right now I am using a Messenger model from DevExpress to notify anyone who cares that the IsSelected property has changed:

private bool _isSelected;
    public virtual bool IsSelected
    {
        get { return _isSelected; }
        set
        {
            if (value != _isSelected)
            {
                _isSelected = value;
                RaisePropertyChanged("IsSelected");
                Messenger.Default.Send(new PointSelectionChangedMessage() { Object = this });
                Messenger.Default.Send(new ChartRefreshRequestedMessage());
            }
            _isSelected = value;
        }
    }

This at least decouples the view model from knowing about the collection, but it kind of muddies the Viewmodel with piping that seems superfluous. It would be nice if I could bind the DataPointSelectionModifier’s SelectedPoints to the same collection that the table is bound to, but it appears that this is Readonly.

Am I missing something? I suppose I can extend the DataPointSelectionModifier to provide something, but I am hoping I am overlooking a feature…

Thanks for your time,
Mike.

Version
4.0.6.8578
  • You must to post comments
0
0

Hi Mike,

It’s a tricky problem to solve. You’re asking vendor A and vendor B to play nicely 🙂

yes, we require IPointmetadata interface on your ‘data-point’ but if you have MVVM setup whats to stop you implementing IPointMetadata on your view model that a row (and a data-point) is bound to?

e.g you don’t modify the DataRow, but the object it binds to.

Can that help?

Best regards,
Andrew

  • Michael Dusoe
    Thanks Andrew, I do that very thing. BizObjectViewModel (BOVM) implements IPointMetadata, and therefore has IsSelected on it. The trouble I am having is related to the wiring up to OnIsSelectedChanged for each of potentially thousands of Datapoints, just so I can add to or remove from the ObservableCollection that the rows are bound to. The Messenger model identified above seems to help, so that the VM that houses the collection only registers to listen once, and any BOVM can Send the message. I was just hoping I overlooked something. Thanks anyway!
  • Andrew
    True, you don’t really want to subscribe to a bazzilion IsSelected changed events… There isn’t a nice neat ‘some selection changed’ event in SciChart, however, there is the DataPointSelectionModiifer.SelectedPointMarkers collection. If you are using our DataPointSelectionModiifer you can subscribe to SelectedPointMarkers.CollectionChanged to get a general notification. But it won’t cover programmatic selection changes.Other than that the solution you have is near optimal. Maybe you could pass all IsSelected changed to a parent class which managed all the selections?
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.