title: Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead when execution twice
body: <p>I have a piece of code doesn't work properly. If I execute the btnNew once there is no problem. If I execute twice I get a error of...</p>
  
  <blockquote>
    <p>Operation is not valid while ItemsSource is in use. Access and modify elements with ItemsControl.ItemsSource instead.</p>
  </blockquote>
  
  <p>Main class</p>
  
  <pre><code>ClassA obj = new ClassA();         
  
  private void btnNew_Click(object sender, RoutedEventArgs e)
  {
      //List strings for clearing and then creating new strings for Title combobox
      ObservableCollection&lt;string&gt; calledList = obj.GetList();
      cbTitle.Items.Clear();
      cbTitle.ItemsSource = calledList;
  }
  </code></pre>
  
  <p>ClassA.cs</p>
  
  <pre><code>private ObservableCollection&lt;string&gt; data = new ObservableCollection&lt;string&gt;();
  
  public ObservableCollection&lt;string&gt; GetList()
  {
      return data;
  }
  
  public void SimpleNew()
  {
      data.Add("A");
      data.Add("B");
  }
  </code></pre>
  
  <p>if I use a if statement in the main class it will eliminate the problem then it will create duplicate strings in the combobox. Then I am asking myself do I need to create a method to handle distinct? I am not sure on this. </p>
  
  <p>This my if statement in the main class</p>
  
  <pre><code>if (cbTitle.Items.Count == 0)
  {
      ObservableCollection&lt;string&gt; calledList = obj.GetList();
      cbTitle.Items.Clear();
      cbTitle.ItemsSource = calledList;
  }
  </code></pre>
  
  <p>When I used try/catch it catches error and shows the message. So this is not good either.</p>
  
  <p>So my question is can anyone tell me how to solve this problem? </p>