Hello.
Referring to the link above, we have modified the ViewModel side to maintain the selection state of chart points.
It works fine for a single chart, but when I have multiple charts, the selection points are interlocked between charts. I would like them to be independent of each other.
I wasn’t sure if there was a problem with my code or with the DataPointSelectionModifier, so does anyone know?
I have attached a code sample and a GIF of a working image.
※To reproduce this, click the three points in order from the top while holding down the control key on “Chart1” to make the three points selected. The color of the points will change from blue to red.
Next, while holding down the control key in “Chart2,” click on the bottom point. Then, in “Chart2,” four points are selected, even though only one point is pressed in total.
That is all. Best regards.
- Naoya Yokoyama asked 11 months ago
- You must login to post comments
Hi there,
There’s nothing static in DataPointSelectionModifier
or SciChartSurface
that would share selected points between chart instances.
You do however declare a DependencyProperty in your custom class like this:
public class DataPointSelectionModifierExtention : DataPointSelectionModifier
{
public ObservableCollection<DataPointInfo> SelectedPointMarkers2
{
get => (ObservableCollection<DataPointInfo>)GetValue(SelectedPointMakers2Property);
set => SetValue(SelectedPointMakers2Property, value);
}
public static readonly DependencyProperty SelectedPointMakers2Property =
DependencyProperty.Register(
nameof(SelectedPointMarkers2),
typeof(ObservableCollection<DataPointInfo>),
typeof(DataPointSelectionModifierExtention),
new PropertyMetadata(new ObservableCollection<DataPointInfo>())); // HERE
This unknowingly creates a single instance of ObservableCollection<DataPointInfo>
and assigns it as the default value of DataPointSelectionModifierExtention.SelectedPointMarkers2
. So if you are getting points shared between charts this could be the reason.
What I suggest:
- Never set an instance of a reference type as the default value in a dependency property (see here for more info)
- Instead, use
this.SetCurrentValue(SelectedPointMakers2Property, new ObservableCollection<DataPointInfo>());
to set the value of the dependency property to a new ObservableCollection. The best place to do this would be yourDataPointSelectionModifierExtention
constructor
Try that. Remove the default value and set it later in the ctor so you have one ObservableCollection instance per DataPointSelectionModifierExtention
instance
Best regards,
andrew
- Andrew Burnett-Thompson answered 11 months ago
- last edited 11 months ago
- You must login to post comments
Please login first to submit.