Is converter on ValueBinding possible?

4 posts, 0 answers
  1. Chris Andrews
    Chris Andrews avatar
    41 posts
    Member since:
    Mar 2010

    Posted 29 Apr 2013 Link to this post

    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
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 02 May 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Mahdi
    Mahdi avatar
    8 posts
    Member since:
    Jan 2014

    Posted 05 Jun 2015 in reply to Petar Marchev Link to this post

    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.

  5. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 10 Jun 2015 Link to this post

    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
Back to Top