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

ValueBinding of index in array

4 Answers 314 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 25 Sep 2013, 07:40 PM
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?



4 Answers, 1 is accepted

Sort by
0
Accepted
Petar Kirov
Telerik team
answered on 01 Oct 2013, 06:12 AM
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 >>
0
Mike
Top achievements
Rank 1
answered on 07 Oct 2013, 08:25 PM
Spot on, thanks...
0
Veli-Pekka
Top achievements
Rank 1
answered on 30 Sep 2015, 10:40 AM

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 :(

 

0
Dinko | Tech Support Engineer
Telerik team
answered on 01 Oct 2015, 11:32 AM
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
Tags
ChartView
Asked by
Mike
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Mike
Top achievements
Rank 1
Veli-Pekka
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or