Pre loader

Using Custom Overview example with multiple y axes

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

1
0

In your custom overview example the width of the grid column used as padding is linked to the width of the y axis.

            <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <!--  Hosts overview control  -->
            <ColumnDefinition Width="{Binding ActualWidthValue, ElementName=proxy, Mode=OneWay, Converter={StaticResource DoubleToGridLengthConverter}}" />
            <!--  Used to bind to parent surface YAxis  -->
        </Grid.ColumnDefinitions>

        <!-- This class is in the Examples Source Code, under your install directory -->
        <helpers:ActualSizePropertyProxy x:Name="proxy" Element="{Binding ElementName=MainChartSurface, Path=YAxis}" />

What do you use for the Path if you have multiple y axes. I have tried objects like AxisAreaLeft with no success.

  • You must to post comments
1
0

I got it to work.

Here is the plot:

enter image description here

Here is the XAML:

            <Grid.RowDefinitions>
            <RowDefinition Height="{Binding ActualYAxesHeightValue, ElementName=PropertyProxy, Mode=OneWay, Converter={StaticResource DoubleToGridLengthConverter}}"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <helpers:TotalSizeOfAxes x:Name="PropertyProxy" Element="{Binding ElementName=FormationChart}" />

And here is where I get size of axes. I mostly copied the ActualSizePropertyProxy class.

    public class TotalSizeOfAxes : FrameworkElement, INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public static readonly DependencyProperty ElementProperty =
        DependencyProperty.Register("Element", typeof(FrameworkElement), typeof(TotalSizeOfAxes),
                                    new PropertyMetadata(null, OnElementPropertyChanged));

    public FrameworkElement Element
    {
        get { return (FrameworkElement)GetValue(ElementProperty); }
        set { SetValue(ElementProperty, value); }
    }

    public double ActualXAxesHeightValue
    {
        get
        {
            var sciChartSurface = Element as SciChartSurface;
            return sciChartSurface == null ? 0.0 : sciChartSurface.XAxes.Sum(axis => axis.ActualHeight);
        }
    }

    public double ActualXAxesWidthValue
    {
        get
        {
            var sciChartSurface = Element as SciChartSurface;
            return sciChartSurface == null ? 0.0 : sciChartSurface.XAxes.Sum(axis => axis.ActualWidth);
        }
    }

    public double ActualYAxesHeightValue
    {
        get
        {
            var sciChartSurface = Element as SciChartSurface;
            return sciChartSurface == null ? 0.0 : sciChartSurface.YAxes.Sum(axis => axis.ActualHeight);
        }
    }

    public double ActualYAxesWidthValue
    {
        get
        {
            var sciChartSurface = Element as SciChartSurface;
            return sciChartSurface == null ? 0.0 : sciChartSurface.YAxes.Sum(axis => axis.ActualWidth);
        }
    }

    private static void OnElementPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ((TotalSizeOfAxes)d).OnElementChanged(e);
    }

    private void OnElementChanged(DependencyPropertyChangedEventArgs e)
    {
        var oldElement = (FrameworkElement)e.OldValue;
        var newElement = (FrameworkElement)e.NewValue;

        newElement.SizeChanged += OnElementSizeChanged;
        var sciChartSurface = newElement as SciChartSurface;
        if (sciChartSurface != null)
        {
            foreach (var axis in sciChartSurface.XAxes)
            {
                var numericAxis = axis as NumericAxis;
                if (numericAxis != null)
                {
                    numericAxis.SizeChanged += numericAxis_SizeChanged;
                }
            }
            foreach (var axis in sciChartSurface.YAxes)
            {
                var numericAxis = axis as NumericAxis;
                if (numericAxis != null)
                {
                    numericAxis.SizeChanged += numericAxis_SizeChanged;
                }
            }
        }

        if (oldElement != null)
        {
            oldElement.SizeChanged -= OnElementSizeChanged;
            sciChartSurface = oldElement as SciChartSurface;
            if (sciChartSurface != null)
            {
                foreach (var axis in sciChartSurface.XAxes)
                {
                    var numericAxis = axis as NumericAxis;
                    if (numericAxis != null)
                    {
                        numericAxis.SizeChanged -= numericAxis_SizeChanged;
                    }
                }
                foreach (var axis in sciChartSurface.YAxes)
                {
                    var numericAxis = axis as NumericAxis;
                    if (numericAxis != null)
                    {
                        numericAxis.SizeChanged -= numericAxis_SizeChanged;
                    }
                }
            }
        }

        NotifyPropertyChange();
    }

    private void numericAxis_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        NotifyPropertyChange();
    }

    private void OnElementSizeChanged(object sender, SizeChangedEventArgs e)
    {
        NotifyPropertyChange();
    }

    private void NotifyPropertyChange()
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs("ActualXAxesHeightValue"));
            PropertyChanged(this, new PropertyChangedEventArgs("ActualXAxesWidthValue"));
            PropertyChanged(this, new PropertyChangedEventArgs("ActualYAxesHeightValue"));
            PropertyChanged(this, new PropertyChangedEventArgs("ActualYAxesWidthValue"));
        }
    }
}
  • Andrew Burnett-Thompson
    That's a great workaround. I think its the only way to do this at present. I must confess I tried this late last night and discovered that because AxisAreaLeft / AxisAreaRight are not dependency properties (but merely getters on a private field), and because they are assigned after the control template loads (and after bindings evaluated), binding to them doesn't work. We could improve this in future, in fact I think we should, but exposing a get/set dependency property invites users to set the property, which is not what we want either.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.