ValueBinding of index in array

5 posts, 1 answers
  1. Mike
    Mike avatar
    28 posts
    Member since:
    Apr 2013

    Posted 25 Sep 2013 Link to this post

    Ok, I figure I'm missing something blindingly obvious here. I have a class, which in turn has a list of floats within it (there is more in the class including a datetime for the category binding):

    public class MyClass
    {
        public string aName ...
        public List<float> aList ...
        ....
    }

    My LineSeries's ItemsSource is bound to an observablecollection of MyClass. Then the ValueBinding is set to "aName". When I do this all is well in the world and I get exactly what I wanted. Now I want to have item in index 1 of the "aList" as a ValueBinding. If I put in "aList[1]" I get an error stating that it can't find the property.

    So where am I wrong please?



  2. Answer
    Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 01 Oct 2013 Link to this post

    Hi Mike,

    RadChartView has two data-binding mechanisms: PropertyNameDataPointBinding and GenericDataPointBinding. These two classes derive from the DataPointBinding base class. When using the first approach you specify the name of the property of the data item to which you want to bind:
    var series = new BarSeries()
    {
        ValueBinding = new PropertyNameDataPointBinding("aName")
    };
    Note that you can not use nested property or array indexing syntax (eg. "prop1.prop2.prop3[8].prop4").

    For binding to nested properties and other more advanced scenarios, you can use the second approach. Here's an example:
    var series = new BarSeries()
    {
        ValueBinding = new GenericDataPointBinding<MyClass, double>
        {
            ValueSelector = (item) => item.aList[0]
        }
    };

    When you specify the binding in XAML like this:
    <telerik:LineSeries CategoryBinding="StringProp"
                  ValueBinding="DoubleProp"
                  ItemsSource="{Binding Data1}"/>

    the strings "StringProp" and "DoubleProp" are implicitly converted to PropertyNameDataPointBindings.

    This means that you will need to specify the series value binding in code-behind (because you can't specify generic data point bindings in XAML).

    For additional information, you can check these two articles (link1, link2).

    I hope this helps.
     
    Regards,
    Petar Kirov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Mike
    Mike avatar
    28 posts
    Member since:
    Apr 2013

    Posted 07 Oct 2013 Link to this post

    Spot on, thanks...
  5. Veli-Pekka
    Veli-Pekka avatar
    1 posts
    Member since:
    Sep 2015

    Posted 30 Sep 2015 in reply to Petar Kirov Link to this post

    Any changes here in two years? Do you have any plans to make binding from XAML support dot notation ( ValueBinding="MyClassProp.ValueProp" )?

     I could create the chart I need fully via XAML, but this handicap forces me to use codebehind to make the binding there :(

     

  6. Dinko
    Admin
    Dinko avatar
    204 posts

    Posted 01 Oct 2015 Link to this post

    Hi,

    I'm afraid we still do not support nested property path or array indexing syntax in the ValueBinding
    property.Currently we don't have plans to implement this functionality.

    Regards,
    Dinko
    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
UI for WPF is Visual Studio 2017 Ready