Hi,
I have a scichart surface defined in xaml like this,
<local:SciChartSurface x:Name="_ChartSurface" Annotations="{Binding ChartAnnotations}">
</local:SciChartSurface>
In the code behind I have ChartAnnotations defined as,
public const string ChartAnnotationsPropertyName = "ChartAnnotations";
private AnnotationCollection _ChartAnnotations = new AnnotationCollection();
public AnnotationCollection ChartAnnotations
{
get { return _ChartAnnotations; }
set
{
if (_ChartAnnotations == value)
return;
_ChartAnnotations = value;
RaisePropertyChanged(ChartAnnotationsPropertyName);
}
}
public ViewModelExample()
{
ChartAnnotations.CollectionChanged += ChartAnnotations_CollectionChanged;
}
void ChartAnnotations_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
RaisePropertyChanged(ChartAnnotationsPropertyName);
}
Than in the code behind, I just initialize and add some annotations to the ChartAnnotations collection to populate my chart. The problem is that my Annotations property on the scichart surface is still null, and the RaisePropertyChanged() is not affecting the Bindings at all. I’m certain that the DataContext is set right as other stuff in the graph works fine. I works when I explicitly set the surface’s Annotations property with my ChartAnnotations collection, but obviously this is less than ideal.
Is there an additional step that I’m missing here?
Thanks
- kewur asked 10 years ago
- last edited 10 years ago
- You must login to post comments
Hi Kewur,
I don’t understand why the AnnotationsCollection is null. This is set in the constructor of the SciChartSurface, so, unless you are setting it to null (possibly via a bad binding? Or binding to a property which has a null value) it should never be null.
Perhaps this alone helps your investigation, but also I wanted to point you to this article on Editing Annotations and keeping track of them in an MVVM application, which describes the proper MVVM architecture to adopt when using Annotations in an MVVM WPF application.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 10 years ago
-
Hi Andrew, Thanks for the help, I was able to get it running by calling InitializeComponent() after I set the annotations, instead of before. Hope this helps someone else. Thanks
- You must login to post comments
Please login first to submit.