Binding SeriesDefinition in code behind?

3 posts, 0 answers
  1. EM
    EM avatar
    21 posts
    Member since:
    Oct 2006

    Posted 25 May 2011 Link to this post


    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?


  2. Yavor
    Yavor avatar
    401 posts

    Posted 30 May 2011 Link to this post

    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.

    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
  3. EM
    EM avatar
    21 posts
    Member since:
    Oct 2006

    Posted 31 May 2011 Link to this post

    Many thanks Yavor,

    works perfectly.

Back to Top