Binding ObservableCollection to ItemSource

2 posts, 0 answers
  1. kl
    kl avatar
    3 posts
    Member since:
    Aug 2008

    Posted 21 Nov 2012 Link to this post

    What is the proper way of coding standard to bind the ObservableCollection to ItemSource?
    The case i'm facing is i have multiple lineseries, therefore, i created an ObservableCollection<IEnumberable><T>> that contains array of ObservableCollection<T>. i make the ObservableCollection<IEnumberable><T>> binded to the itemsource of lineSeries with INotifyPropertyChanged.

    Code Snippet:
    XAML:
    <chartView:LineSeries x:Name="Item1" ItemsSource="{Binding Item[0]}" ValueBinding="Value" CategoryBinding="Counter" />
    <chartView:LineSeries x:Name="Item2" ItemsSource="{Binding Item[1]}" ValueBinding="Value" CategoryBinding="Counter" />
    <chartView:LineSeries x:Name="Item3" ItemsSource="{Binding Item[2]}" ValueBinding="Value" CategoryBinding="Counter" />
    <chartView:LineSeries x:Name="Item4" ItemsSource="{Binding Item[3]}" ValueBinding="Value" CategoryBinding="Counter" />
    <chartView:LineSeries x:Name="Item5" ItemsSource="{Binding Item[4]}" ValueBinding="Value" CategoryBinding="Counter" />

    C#
    public ObservableCollection<IEnumerable<GraphPlot>> Item
    {
          get { return m_item; }
          set
          {
               m_item = value;
               OnPropertyChanged("Item");
          }
    }

    i have an error "observablecollection collection was modified enumeration operation may not execute" using the code above.
    is this the right way to bind it to multiple itemsource with only 1 Properties at real-time? any recommendation?

  2. Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 26 Nov 2012 Link to this post

    Hi,

    Given the information you've provided it is not possible to determine the cause of the problem. I have attached a test project, created using the code you provided. The project runs as expected. 

    If the problem persists, please send more information, so we can track down the problem locally (you can open a support ticket and attach a project that reproduces this issue).
     
    All the best,
    Petar Kirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top