Hello,
I have this in XAML
ViewModel
private ObservableCollection _annotations = new ObservableCollection();
This works great but we have few chart that we need to add dynamically in initial constructor of the window.
When we do SetBinding in code behind it doesn’t work. What am I missed. Please help
Binding annatBinding = new Binding(“Annotations”);
annatBinding.Mode = BindingMode.TwoWay;
chartOne.SetBinding(SciStockChart.AnnotationsProperty, annatBinding);
May be I should use AnnotationsBinding but need guidance
thanks
- Praveen D asked 2 weeks ago
- last edited 2 weeks ago
- You must login to post comments
Hi Praveen,
Thanks for your inquiry.
Unfortunately, it’s not clear enough what exactly you are trying to achieve. Could you please provide us with more details?
Some mockups could also be helpful.
If you wish to bind an Annotation collection, though, you can use the approach shown in our “Axis Binding and Annotations Binding” example.
Here is a link:
https://www.scichart.com/example/wpf-chart/wpf-chart-axis-binding-annotations-binding-mvvm/
Kind regards,
Lex,
SciChart Technical Support Engineer
- Lex answered 2 weeks ago
- You must login to post comments
Some how some code didn’t post .
I am trying to do the same instead of XAML
I need to create in code behind in CS
I have same properties as in my viewmodel as in example i.e
public ObservableCollection AnnotationViewModels { get; set; }
public ObservableCollection RenderableSeries { get; set; }
But instead of binding in XAML like in example
I am trying to create a instance of SciChartSurface in Code Behind
public partial class HomeWindow : Window
{
public HomeWindow()
{
InitializeComponent();
AddChart();
}
private void AddChart()
{
SciChartSurface sciChart= new SciChartSurface ();
//…. more code
Binding annotBinding = new Binding(“AnnotationViewModels ”);
annotBinding .Mode = BindingMode.TwoWay;
sciChart.SetBinding(SciStockChart.AnnotationsProperty, annotBinding );
// layoutGrid is WPF Grid
layoutGrid.Children.Add(sciChart)
Grid.SetRow(sciChart, 1);
};
//…. more code
}
Also in the example
https://www.scichart.com/documentation/win/current/webframe.html#TradingAnnotationCreationModifier.html
I am trying to do the same as above XAML in CS code behind
I am able to do most of the Modifier in code behind here my code snippet
//Create a Binding for enabling Annotation
Binding isAnnotCreatebinding = new Binding(“IsAnnotationCreationEnable”);
isAnnotCreatebinding.Mode = BindingMode.TwoWay;
//Create MVVM version of Modifier
AnnotationCreationModifierMVVM annotationCreationModifierMVVM = new AnnotationCreationModifierMVVM()
{
Name = “annotationCreation”,
YAxisId= “yAxis0”,
ReceiveHandledEvents=true,
};
// Binding enable draw same as XAML – IsEnabled = “{Binding IsAnnotationCreationEnable, Mode=TwoWay}”
annotationCreationModifierMVVM.SetBinding(AnnotationCreationModifierMVVM.IsEnabledProperty, isAnnotCreatebinding);
annotationCreationModifierMVVM.AnnotationViewModelType = typeof(LineAnnotationViewModel);
ModifierGroup chartModifierGroup = new ModifierGroup(
new LegendModifier() { ShowLegend = true },
new SeriesSelectionModifier() { IsEnabled = false, Visibility = Visibility.Hidden },
new SeriesValueModifier() { IsEnabled = true, YAxisId =”yAxis0″ },
new SeriesValueModifier() { IsEnabled = true, YAxisId = “yAxis1” },
new MouseWheelZoomModifier() { ActionType=ActionType.Zoom , ReceiveHandledEvents = true , GrowFactor=.001, XyDirection= XyDirection.XDirection},
new CursorModifier() { SourceMode = SourceMode.AllSeries, ReceiveHandledEvents = true, IsEnabled = true, ShowAxisLabels = true, ShowTooltip = true },
annotationCreationModifierMVVM,
new RolloverModifier() { ReceiveHandledEvents = true }
, new ZoomPanModifier() { ReceiveHandledEvents = true }, new ZoomExtentsModifier() { ReceiveHandledEvents = true }
)
{ MouseEventGroup = “MySharedMouseGroup”, ReceiveHandledEvents = true, IsSynchronized = true, };
sciChart.ChartModifier = chartModifierGroup ;
All the modifiers work great but I am not able to Binding to IsAnnotationCreationEnable and AnnotationViewModelType properties of the ViewModel
Please guide
- Praveen D answered 2 weeks ago
- last edited 2 weeks ago
- Hi Praveen, Thank you for the details. We’ll have a look and will get back to you as soon as we have an update. Kind regards, Lex
- You must login to post comments
Yesterday I posted clarification and I not sure what happened to the post
- Praveen D answered 2 weeks ago
- last edited 2 weeks ago
- Hi Praveen, New SciChart Forums questions and replies are now being moderated before publishing. Your reply has already been approved. Kind regards, Lex
- You must login to post comments
Hi Praveen,
We discussed your inquiry.
The provided sample code looks correct.
Thus, to provide a proper solution, we would need to investigate the reported issue on our side.
Could you please prepare a small working sample project reproducing the described issue and send it to us for investigation?
Thanks in advance,
Lex
- Lex answered 1 week ago
- You must login to post comments
Please login first to submit.