SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
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.
I got it to work.
Here is the plot:
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"));
}
}
}
Please login first to submit.