title: Binding to WPF ViewModel properties
body: <p>I'm just playing around with WPF and MVVM, and I have made a simple app that displays a Rectangle that changes color whenever Network availability changes.</p>
  
  <p>But when that happens, I get this error: <code>Cannot use a DependencyObject that belongs to a different thread than its parent Freezable.</code></p>
  
  <p>Code</p>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window1" Height="400" Width="600"&gt;
  &lt;DockPanel LastChildFill="True"&gt;
      &lt;Rectangle x:Name="networkStatusRectangle" Width="200" Height="200" Fill="{Binding NetworkStatusColor}" /&gt;
  &lt;/DockPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Code-behind</strong></p>
  
  <p>using System.Windows;
  using WpfApplication1.ViewModels;</p>
  
  <pre><code>namespace WpfApplication1
  {
      /// &lt;summary&gt;
      /// Interaction logic for Window1.xaml
      /// &lt;/summary&gt;
      public partial class Window1 : Window
      {
          public Window1()
          {
              InitializeComponent();
              DataContext = new NetworkViewModel();
          }
      }
  }
  </code></pre>
  
  <p><strong>ViewModel</strong></p>
  
  <pre><code>using System.ComponentModel;
  using System.Net.NetworkInformation;
  using System.Windows.Media;
  
  namespace WpfApplication1.ViewModels
  {
      public class NetworkViewModel : INotifyPropertyChanged
      {
          private Brush _NetworkStatusColor;
  
          public Brush NetworkStatusColor
          {
              get { return _NetworkStatusColor; }
              set
              {
                  _NetworkStatusColor = value;
                  NotifyOfPropertyChange("NetworkStatusColor");
              }
          }
  
          public NetworkViewModel()
          {
              NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
          }
  
          protected void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
          {
              if (e.IsAvailable)
              {
                  this.NetworkStatusColor = new SolidColorBrush(Colors.Green);
              }
              else
              {
                  this.NetworkStatusColor = new SolidColorBrush(Colors.Red);
              }
          }
  
          public event PropertyChangedEventHandler PropertyChanged = delegate { };
  
          public void NotifyOfPropertyChange(string propertyName)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  }
  </code></pre>
  
  <p>I assume that I should change the NetworkStatusColor property by invoking something?</p>