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

Binding SeriesDefinition in code behind?

2 Answers 102 Views
Chart
This is a migrated thread and some comments may be shown as answers.
EM
Top achievements
Rank 1
EM asked on 25 May 2011, 10:26 PM
Hello,

I'm creating a SeriesMapping in code behind as I need to dynamically change the series in chart depending on a number of other factors.  I need to bind a specific property to my view model, specifically in this case, I need to bind ShowItemsLabel on the SeriesDefinition from code behind.  My code goes something like this:

seriesMapping.SeriesDefinition = new BarSeriesDefinition() {ItemLabelFormat = "#Y{###,###,##0}"};
var binding = new Binding("ShowItemLabels");

The question is how would I use a SetBinding() to bind the new series definition using the two lines above?

Thanks,

E.

2 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 30 May 2011, 08:50 AM
Hello EM,

You can create a binding in code behind and bind the SeriesDefinition.ShowItemLabelsProperty to your view model. SeriesDefinition is the base class for all series definitions and ShowItemLabelsProperty is the dependency property that you'll need for the binding expression. You can use BindingOperations.SetBinding(..) helper method to create the binding in code behind. The final code can look like this:

SeriesDefinition seriesDefinition = new BarSeriesDefinition() { ItemLabelFormat = "#Y{###,###,##0}" };
seriesMapping.SeriesDefinition = seriesDefinition;
var binding = new Binding("ShowItemLabels");
BindingOperations.SetBinding(seriesDefinition, SeriesDefinition.ShowItemLabelsProperty, binding);

Now the ShowItemLabels is bound to your view model.


Regards,
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
EM
Top achievements
Rank 1
answered on 31 May 2011, 01:30 PM
Many thanks Yavor,

works perfectly.

E.
Tags
Chart
Asked by
EM
Top achievements
Rank 1
Answers by
Yavor
Telerik team
EM
Top achievements
Rank 1
Share this question
or