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

Is converter on ValueBinding possible?

3 Answers 171 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Chris Andrews
Top achievements
Rank 1
Chris Andrews asked on 29 Apr 2013, 11:39 PM
Hello All,

I was just wondering if there is a way to support the following with the RadCartesianChart:

In my example, I am binding the vertical axis to an "Altitude" property on my underlying data.  The data is in meters.  Based on an application setting, I would like the ability to convert the value to feet when needed.

I do have access to the data contract and I can add another property for feet, however I was just wondering if I could avoid the multiple properties.

Thanks,
Chris

3 Answers, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 02 May 2013, 03:58 PM
Hello Chris,

When declared in XAML the xaml parser will create a PropertyNameDataPointBinding:
<telerik:BarSeries ValueBinding="Value" />

The ValueBinding property is of type DataPointBinding and it is not a simple string. So the xaml parser will create for you a PropertyNameDataPointBinding with the PropertyName set to "Value". This way the values of your items will be extracted from the Value property.

You can use code behind to set a GenericDataPointBinding. You can set the ValueSelector to be whatever function you need - in one case it would be to simply return the Meters property and in another case you can do some calculations instead:
series.ValueBinding = new GenericDataPointBinding<YourBusinessItem, double>()
{
 ValueSelector = item => item.Meters,
};
  
series.ValueBinding = new GenericDataPointBinding<YourBusinessItem, double>()
{
 ValueSelector = item => item.Meters / 3,
}

You see that the generic binding is much more flexible but it requires some code behind. Personally I think that the simplest solution would be to introduce a new property in your business item (just as you have mentioned). After all, the Feet seems to be a property of your items. Let us know if we can assist you further.

Kind regards,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mahdi
Top achievements
Rank 1
answered on 05 Jun 2015, 09:18 PM

Hello Petar Marchev,

I have a question about special situation.

If I have an indexed property like ObjectA.ObjectB["NameC"] and at runtime want to bind that to ValueBinding what can I do?

Please remeber that until runtime moment I don't know anything about this property except its path.

Thank you in advance.

0
Petar Marchev
Telerik team
answered on 10 Jun 2015, 07:04 AM
Hello Mahdi,

If you use the ValueBinding in xaml (<t:LineSeries ValueBinding="Prop1" />), the xaml parser will create an object of type PropertyNameDataPointBinding and assign it to the ValueBinding property. Then, the series will look for a property with the name of Prop1 in the items you have passed to it. You cannot use indexed properties as "Prop1.Prop2" with the PropertyNameDataPointBinding. You can use the GenericDataPointBinding as demonstrated earlier. If you do not know the exact type of the data items but you do know the name of the property, you can use reflection to get the value.

Regards,
Petar Marchev
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Chart
Asked by
Chris Andrews
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Mahdi
Top achievements
Rank 1
Share this question
or