This is a migrated thread and some comments may be shown as answers.

LabelStep & Binding

6 Answers 106 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Yves
Top achievements
Rank 1
Yves asked on 16 Aug 2010, 02:14 PM
Hi,

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

Sort by
0
Yavor
Telerik team
answered on 17 Aug 2010, 03:55 PM
Hi Yves,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yves
Top achievements
Rank 1
answered on 18 Aug 2010, 08:29 AM
Hi,

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
0
Yavor
Telerik team
answered on 19 Aug 2010, 05:13 PM
Hello Yves,

 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.

Best wishes,
Yavor Ivanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yves
Top achievements
Rank 1
answered on 20 Aug 2010, 08:47 AM
Hi,

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
0
Accepted
Yavor
Telerik team
answered on 25 Aug 2010, 06:13 PM
Hello Yves,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yves
Top achievements
Rank 1
answered on 26 Aug 2010, 07:44 AM
Ok, Thanks.

I just will apply an angle rotation and it will become a little more readable. Thanks anyway :)
Tags
Chart
Asked by
Yves
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Yves
Top achievements
Rank 1
Share this question
or