I'm using the RadChart from Telerik in WPF and I have a problem when I want to specify the MaxValue, MinValue and Step for an additional Y-axis.
It works fine if I hardcode the values like this (the relevant part is the last four lines):
<Controls:AxisY MinorTicksVisibility="Hidden"
DefaultLabelFormat="#VAL{#,##0}"
Title="{UI:Language @{xCubicMetrePerHourSymbol}}"
MajorGridLinesVisibility="Hidden" StripLinesVisibility="Visible"
AxisName="CubicMetreAxis"
AutoRange="False"
MaxValue="10000"
MinValue="0"
Step="0">
But since I want to change the MinValue, MaxValue and Step depending on the values in the series, I have to bind it this way using properties from a ViewModel object (which is supposed to be my inherited DataContext):
<Controls:AxisY MinorTicksVisibility="Hidden"
DefaultLabelFormat="#VAL{#,##0}"
Title="{UI:Language @{xCubicMetrePerHourSymbol}}"
MajorGridLinesVisibility="Hidden" StripLinesVisibility="Visible"
AxisName="CubicMetreAxis"
AutoRange="False"
MaxValue="{Binding Path=MyMaxValue}"
MinValue="{Binding Path=MyMinValue}"
Step="{Binding Path=MyStep}">
But it seems that the DataContext cannot be seen / set from the additional Y-axis from what I've gathered using Snoop.
I get the following error message (the same message for each of the bindings):
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or
FrameworkContentElement for target element. BindingExpression:Path=MyMaxValue;
DataItem=null; target element is 'AxisY' (HashCode=47300984); target property is
'MaxValue' (type 'Double')
I thought I had made a mistake somewhere and have searched for hours, but I discovered something weird: if I use those bindings in the "original" Y-axis, everything works perfectly. The code is exactly the same for both axes. The only difference is in the parent elements.
This works:
<Controls:ChartArea.AxisY>
<Controls:AxisY MinorTicksVisibility="Hidden"
DefaultLabelFormat="#VAL{#,##0}"
Title="{UI:Language @{GigaJoulePerHourSymbol}}"
MajorGridLinesVisibility="Hidden"
StripLinesVisibility="Visible"
AutoRange="False"
MaxValue="{Binding Path=MyMaxValue}"
MinValue="{Binding Path=MyMinValue}"
Step="{Binding Path=MyStep}">
<Controls:AxisY.AxisStyles>
<Controls:AxisStyles TitleStyle="{StaticResource TranslatedAxisStyle}" />
</Controls:AxisY.AxisStyles>
</Controls:AxisY>
</Controls:ChartArea.AxisY>
This doesn't:
<Controls:ChartArea.AdditionalYAxes>
<Controls:AxisY MinorTicksVisibility="Hidden"
DefaultLabelFormat="#VAL{#,##0}"
Title="{UI:Language @{xCubicMetrePerHourSymbol}}"
MajorGridLinesVisibility="Hidden"
StripLinesVisibility="Visible"
AxisName="CubicMetrePerHourAxis"
AutoRange="False"
MaxValue="{Binding Path=MyMaxValue}"
MinValue="{Binding Path=MyMinValue}"
Step="{Binding Path=MyStep}">
<Controls:AxisY.AxisStyles>
<Controls:AxisStyles TitleStyle="{StaticResource TranslatedAxisStyle}" />
</Controls:AxisY.AxisStyles>
</Controls:AxisY>
</Controls:ChartArea.AdditionalYAxes>
The element itself is exactly the same, except that the second one has a name and the title is different, but I tested and it doesn't actually affect anything. The only difference is that the parent elements are different.
I'd like to know why the AxisY sees the DataContext and can bind properly while the AdditionalYAxis cannot.