On my RadChart i would like to "control" x labelstep thank to a property in a ViewModel (as you see I'm using MVVM pattern).
But when i try to use this mehod, i've got this message :
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Intervalle; DataItem=null; target element is 'AxisX' (HashCode=6253391); target property is 'LabelStep' (type 'Int32')
It seems that RadChart is loosing DataContext juste for this property. Any idea ? :D I probably should affect DataContext to "AxisX" but i don't know how to do it.
Here is my code :
<
telerik:ChartArea
LegendName
=
"CustomLegend"
Name
=
"chArea"
NoDataString
=
"Aucune données"
DataContext
=
"{Binding ElementName=brd1,Path=DataContext}"
>
<
telerik:ChartArea.AxisX
>
<
telerik:AxisX
MajorGridLinesVisibility
=
"Collapsed"
Title
=
"Heures"
IsZeroBased
=
"True"
AutoRange
=
"True"
LabelStep
=
"{Binding Intervalle}"
/>
</
telerik:ChartArea.AxisX
>
<
telerik:ChartArea.AxisY
>
<
telerik:AxisY
MajorGridLinesVisibility
=
"Visible"
MinorTicksVisibility
=
"Visible"
Title
=
"Hits Lus"
AutoScale
=
"True"
/>
</
telerik:ChartArea.AxisY
>
</
telerik:ChartArea
>
Thank's !
6 Answers, 1 is accepted
Your scenario is working well in Silverlight, but due to the difference between Silverlight and WPF Binding mechanisms it does not work in WPF. LabelStep is a DependencyProperty of Axis, which is a FrameworkElement. This is ok in Silverlight, but it is not supported in WPF. You can find more information here.
Sincerely yours,yivanov
the Telerik team
Thank's for your reply, for sure WPF and Silverlight doesn't have the same behavior (Unfortunately...).
As i tought that the problem came from my property I've tryed this, just for fun :
<
telerik:AxisX
MajorGridLinesVisibility
=
"Collapsed"
Title
=
"Heures"
IsZeroBased
=
"True"
AutoRange
=
"True"
LabelStep
=
"{Binding ElementName=RadChart1,Path=Width}"
Step
=
"5"
/>
And I've got the same problem It is not able to bind labelStep to this property. I've also tryed this but for the same result :
<
TextBlock
Text
=
"{Binding Intervalle}"
Visibility
=
"Collapsed"
/>
<!-- ... -->
<
telerik:AxisX
MajorGridLinesVisibility
=
"Collapsed"
Title
=
"Heures"
IsZeroBased
=
"True"
AutoRange
=
"True"
LabelStep
=
"{Binding RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type TextBlock}}, Path=Text}"
Step
=
"5"
/>
I've got a little bit different message :
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.TextBlock', AncestorLevel='1''. BindingExpression:Path=Text; DataItem=null; target element is 'AxisX' (HashCode=29410778); target property is 'LabelStep' (type 'Int32')
I've made another thread about a similar problem here :
http://www.telerik.com/community/forums/wpf/chart/datatrigger-on-linecolor.aspx
As you see, I've fxed it with adding a property to force DataContext. Is there any way to make the same things ? I mean, is there a possiility to edit AxisX to force a new DataContext or something like that ?
I'm not sure to be very clear :)
Thank's
You have an interesting idea, but unfortunately it hits the same limitation of WPF as when binding to property in your ViewModel. Your second proposal for binding expects that AxisX's ancestor is TextBlock as in markup. On runtime, on the other hand, AxisX is not added to the visual tree and thus the FindAncestor binding expression fails. I have attached an image showing the visual tree of a sample application to give you some insight on the RadChart runtime behavior.
This behavior comes from the difference in the current implementation of the binding model of WPF and Silverlight.
Yavor Ivanov
the Telerik team
thanks for reply. I understand now why it doesn't work with calling ancestor :) .
PART_AxisX is it the part that I have to style ? (I would like to add DataContext in some of control in this PART for testing if it works) If yes, how can I do it ? Actually, to be honest, I'm not familiar with telerik control, in addition I developp WPF application only since three months.
Thanks
EDIT : I'm using RadControls for WPF 2009 Q2
The axis visual (PART_AxisX) is not exposed through the API but rather used internally by RadChart. Unfortunately, due to the current implementation of the binding mechanisms of WPF, LabelStep cannot be set through binding.
All the best,
Yavor Ivanov
the Telerik team
I just will apply an angle rotation and it will become a little more readable. Thanks anyway :)