I’m trying to dynamically create chart surfaces and renderable series, but I’m having trouble binding one of the axes to another one, like you would do with this code in XAML:
<s:CategoryDateTimeAxis VisibleRange="{Binding ElementName=priceChart,
Path=XAxis.VisibleRange,
Mode=TwoWay}" />
I need to accomplish the same thing directly in C# but there are no methods related to binding at all. From the MSDN reference pages I’ve seen that any element that extends FrameworkElement has the Binding property, but it seems the axes don’t extend from that.
Could someone help me out in binding this axis to another axis (for the record, the other one is defined in XAML)?
- Sam Stenvall asked 9 years ago
- You must login to post comments
Hi Sam,
If you cast your SciChartSurface.XAxis to CategoryDateTimeAxis (or AxisBase, or NumericAxis depending on type) it is a FrameworkElement and you should be able to do bindings in code.
E.g. from MSDN
var myViewModel = new SomeViewModel() {VisibleRange = new IndexRange(0, 100); }
Binding visibleRangeBinding = new Binding("VisibleRange");
visibleRangeBinding.Source = myViewModel;
((CategoryDateTimeAxis)sciChartSurface.XAxis).SetBinding(VisibleRangeProperty, visibleRangeBinding);
Best regards,
Andrew
- Andrew Burnett-Thompson answered 9 years ago
- You must login to post comments
Awesome, I guess I should have thought of that! Here’s the complete code for future reference:
var macdSurface = new SciChartSurface();
// Create a binding for the X axis
Binding visibleRangeBinding = new Binding("VisibleRange");
visibleRangeBinding.Source = mainWindow.priceChart.XAxis;
visibleRangeBinding.Mode = BindingMode.TwoWay;
// Create and bind
macdSurface.XAxis = new CategoryDateTimeAxis();
((CategoryDateTimeAxis)macdSurface.XAxis).SetBinding(CategoryDateTimeAxis.VisibleRangeProperty, visibleRangeBinding);
- Sam Stenvall answered 9 years ago
- You must login to post comments
Please login first to submit.