Pre loader

Create VisibleRange binding in code instead of XAML

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

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)?

  • You must to post comments
0
0

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

  • You must to post comments
0
1

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);
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies