SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
I making MVVM application.
I want to Bind SelectedPointMarkers of DataPointSelectionModifier.
But SelectedPointMarkers is readonly property.
Therefore, I couldn’t bind.
How can I bind it?
I think our DataPointSelectionModifier example binds to this property – but we bind to an existing collection.
Look here:
WPF Chart Data-Point Selection
and in the code…
<ListBox ItemsSource="{Binding Source={x:Reference Name=PointMarkersSelectionModifier}, Path=SelectedPointMarkers}">
Best regards
Andrew
Thank you for your reply.
How to ask questions was not good.
We understand that Bind between controls in View is possible.
I want to Bind to the property of ViewModel, is it possible?
It was possible to solve by inheriting DataPointSelectionModifier and creating your own DependencyProperty for SelectedPointMarkers2.
Thanks a lot.
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>()));
public DataPointSelectionModifierExtention()
{
base.SelectedPointMarkers.CollectionChanged += SelectedPointMakers_CollectionChanged;
}
private void SelectedPointMakers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
foreach (var item in e.NewItems.Cast<DataPointInfo>())
{
this.SelectedPointMarkers2.Add(item);
}
break;
case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
SelectedPointMarkers2.Clear();
break;
case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
foreach (var item in e.OldItems.Cast<DataPointInfo>())
{
this.SelectedPointMarkers2.Remove(item);
}
break;
case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
default:
throw new ApplicationException();
}
}
}
Please login first to submit.