Hi,
Was hoping you could point me in the right direction. I’m trying to create horizontal line annotations on demand using MVVM but have become stuck. I’ve have them working in MVVM when the chart loads but not when a button is clicked although I have achieved this using code behind.
I’ve tried using an observable collection of AnnotationCollection type but am struggling to add the horizontal lines annotations to it as they are of a different type.
Any pointers in the right direction would be much appreciated!
Thanks,
Tim
Example of MVVM
TradeAnnotations = CreateHorizontalAnnotations();
private AnnotationCollection _annotations;
public AnnotationCollection TradeAnnotations
{
get { return _annotations; }
set
{
_annotations = value;
OnPropertyChanged("TradeAnnotations");
}
}
private static AnnotationCollection CreateHorizontalAnnotations()
{
//var annotations = new AnnotationCollection();
var annotations = new AnnotationCollection();
Color strokeColor = (Color)ColorConverter.ConvertFromString("#008B45");
Brush strokeBrush = new SolidColorBrush(strokeColor);
HorizontalLineAnnotation annotation = new HorizontalLineAnnotation();
annotation.ShowLabel = true;
annotation.LabelPlacement = LabelPlacement.Axis;
annotation.HorizontalAlignment = HorizontalAlignment.Stretch;
annotation.IsEditable = true;
annotation.SnapsToDevicePixels = true;
annotation.Stroke = strokeBrush;
annotation.X1 = DateTime.Now;
annotation.Y1 = 129;
annotations.Add(annotation);
return annotations;
}
Example of code behind
private void CreateHorizontalAnnotations(object sender, System.Windows.RoutedEventArgs e)
{
//var annotations = new AnnotationCollection();
var annotationCollection = new AnnotationCollection();
Color strokeColor = (Color)ColorConverter.ConvertFromString("#008B45");
Brush strokeBrush = new SolidColorBrush(strokeColor);
HorizontalLineAnnotation annotation = new HorizontalLineAnnotation();
annotation.ShowLabel = true;
annotation.LabelPlacement = LabelPlacement.Axis;
annotation.HorizontalAlignment = HorizontalAlignment.Stretch;
annotation.IsEditable = true;
annotation.SnapsToDevicePixels = true;
annotation.Stroke = strokeBrush;
annotation.X1 = DateTime.Now;
annotation.Y1 = 129;
this.priceChart.Annotations.Add(annotation);
}
- Tim Douglas asked 10 years ago
- last edited 10 years ago
- You must login to post comments
Hi Tim,
There are lots and lots of examples of best practices with SciChart & MVVM Best Practices. Just do a quick search for SciChart MVVM on google. Here are the top 5:
- Databinding Annotations with MVVM
- Best practices for SciChart ViewModels in MVVM | SciChart
- Best Practies for SciChart MVVM (2)
- Tag: MVVM on SciChart Forums
- Editing annotations and keeping track of them in an mvvm application
This last one (5) is probably the most helpful for you. Let me know if this helps!
Best regards,
Andrew
- Andrew Burnett-Thompson answered 10 years ago
- You must login to post comments
Please login first to submit.