title: How to update UI when ObservableCollection updated?
body: <p>I have simple app, where ObservableCollection is updating in code and when new item added the UI is updated too. To update UI i am using a <strong>Dispatcher</strong> which is passed as a property to ViewModel. My code is works, but i don't know right i am or not.</p>
  
  <p>Here is the code:</p>
  
  <p><strong>MainWindow.xaml.cs</strong></p>
  
  <pre><code>/// &lt;summary&gt;
  /// Логика взаимодействия для MainWindow.xaml
  /// &lt;/summary&gt;
  public partial class MainWindow : Window
  {
      MainWindowViewModel model = new MainWindowViewModel();
  
      public MainWindow()
      {
          InitializeComponent();
          this.DataContext = model;
          this.model.dispatcher = this.Dispatcher;    
      }
  
      private void Button_Click(object sender, RoutedEventArgs e)
      {
          string url = urlToCheck.Text;
  
          Task task = new Task(() =&gt;
          {
              model.GetUrls(url);
          });
  
          task.ContinueWith((previousTask) =&gt;
          {
              label.Content = "Все ссылки собраны.";
          },
          TaskScheduler.FromCurrentSynchronizationContext());
  
          label.Content = "Идёт сбор ссылок...";
          task.Start();
      }
  }
  </code></pre>
  
  <p><strong>MainWindowViewModel.cs</strong></p>
  
  <pre><code> class MainWindowViewModel
  {
      public ObservableCollection&lt;Url&gt; Urls { get; set; }
      public bool NeedToGetResponseForChildUrls { get; set; }
      public bool NeedToDeletePreviousResults { get; set; }
      public Dispatcher dispatcher;
  
      some code.....................
  
  
          **and something like this i am updating ObservableCollection:**
  
          if (NeedToDeletePreviousResults)
              {
                  dispatcher.Invoke(() =&gt;
                  {
                      Urls.Clear();
                  });
  
              }
  </code></pre>
  
  <p><strong>Url.cs</strong></p>
  
  <pre><code>    using System.Collections.ObjectModel;
  using System.ComponentModel;
  
  namespace CheckUrl
  {
      public class Url : INotifyPropertyChanged
      {
          private string _absoluteUrl;
          public string AbsoluteUrl
          {
              get { return _absoluteUrl; }
              set
              {
                  if (_absoluteUrl != value)
                  {
                      _absoluteUrl = value;
                      OnPropertyChanged("AbsoluteUrl");
                  }
              }
          }
  
          private int _responseStatusCode;
          public int ResponseStatusCode
          {
              get { return _responseStatusCode; }
              set
              {
                  if (_responseStatusCode != value)
                  {
                      _responseStatusCode = value;
                      OnPropertyChanged("ResponseStatusCode");
                  }
              }
          }
  
          private string _responseStatusDescription;
          public string ResponseStatusDescription
          {
              get { return _responseStatusDescription; }
              set
              {
                  if (_responseStatusDescription != value)
                  {
                      _responseStatusDescription = value;
                      OnPropertyChanged("ResponseStatusDescription");
                  }
              }
          }
  
          public enum Status { Working, Broken };
  
          private Status _urlStatus;
          public Status UrlStatus
          {
              get { return _urlStatus; }
              set
              {
                  if (_urlStatus != value)
                  {
                      _urlStatus = value;
                      OnPropertyChanged("UrlStatus");
                  }
              }
          }
  
          private string _color;
          public string Color
          {
              get { return _color; }
              set
              {
                  if (_color != value)
                  {
                      _color = value;
                      OnPropertyChanged("Color");
                  }
              }
          }
  
          private ObservableCollection&lt;ChildUrl&gt; _childUrlsValue = new ObservableCollection&lt;ChildUrl&gt;();
          public ObservableCollection&lt;ChildUrl&gt; ChildUrls
          {
              get
              {
                  return _childUrlsValue;
              }
              set
              {
                  _childUrlsValue = value;
              }
          }
  
          /// &lt;summary&gt;
          /// Конструктор класса Url.
          /// &lt;/summary&gt;
          public Url(string absoluteUrl, int responseStatusCode, string responseStatusDescription, Status urlStatus, string color)
          {
              this.AbsoluteUrl = absoluteUrl;
              this.ResponseStatusCode = responseStatusCode;
              this.ResponseStatusDescription = responseStatusDescription;
              this.UrlStatus = urlStatus;
              this.Color = color;
          }
  
          public event PropertyChangedEventHandler PropertyChanged;
  
          public void OnPropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
              { 
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
              }
          }
      }
  }
  </code></pre>