How to set the ItemsSource property of a SeriesMapping in code-behind

3 posts, 1 answers
  1. David
    David avatar
    57 posts
    Member since:
    Apr 2011

    Posted 27 Dec 2011 Link to this post

    Hi,

    I'm looking to dynamically set the ItemsSource property of a SeriesMapping in code-behind. Here's the XAML I'm trying to achieve:
    <telerik:SeriesMapping
        x:Name="EventTypeSeries"
        ItemsSource="{Binding EventAlarmLog}">

    The code I'd like to use is as follows:
    EventTypeSeries.SetBinding(SeriesMapping.ItemsSourceProperty, "EventAlarmLog")

    However, there is no function "SetBinding" for a SeriesMapping. I am able to do this in code-behind for the entire chart (which I am doing right now), however I'd like to chart a series from a separate data source and specify bind the "ItemsSource" property of the individual series in code-behind (so that the "ItemsSource" can be dynamically built). How can I do this?

    Kind regards,
    Dave.
  2. Answer
    Bartholomeo Rocca
    Bartholomeo Rocca avatar
    247 posts
    Member since:
    May 2006

    Posted 28 Dec 2011 Link to this post

    Hello Dave,

    You should be able to achieve the desired effect via the BindingOperations.SetBinding(...) static method -- this is the way to attach a binding to an arbitrary DependencyObject that may not expose its own SetBinding method.


    Greetings,
    Bart.
  3. UI for WPF is Visual Studio 2017 Ready
  4. David
    David avatar
    57 posts
    Member since:
    Apr 2011

    Posted 28 Dec 2011 Link to this post

    Hi Bart,

    Great answer! Here's the code I ended up using:
    BindingOperations.SetBinding(EventTypeSeries, SeriesMapping.ItemsSourceProperty, New Binding("EventAlarmLog"))

    Kind regards,
    Dave.
Back to Top