title: How can I access my ViewModel from code behind
body: <p>I don't understand how I can create a command to create a MVVM clickable rectangle. Here is my code:</p>
  
  <pre><code>&lt;Rectangle x:Name="Color01" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="10,29,0,0" Stroke="Black" VerticalAlignment="Top" Width="100" MouseDown="Color_MouseDown" /&gt;
  &lt;Rectangle x:Name="Color02" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="115,29,0,0" Stroke="Black" VerticalAlignment="Top" Width="100"/&gt;
  &lt;Rectangle x:Name="Color03" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="220,29,0,0" Stroke="Black" VerticalAlignment="Top" Width="100"/&gt;
  &lt;Rectangle x:Name="Color04" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="325,29,0,0" Stroke="Black" VerticalAlignment="Top" Width="100"/&gt;
  </code></pre>
  
  <p>On my first rectangle you can see I created a code behind event. First I don't know how to access my ViewModel from the code behind. Two it's not really MVVM.</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      /// &lt;summary&gt;
      /// Initializes a new instance of the MainWindow class.
      /// &lt;/summary&gt;
      public MainWindow()
      {
          InitializeComponent();
          Closing += (s, e) =&gt; ViewModelLocator.Cleanup();
      }
  
      private void Color_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
      {
          // So what ???
      }
  }
  </code></pre>
  
  <p>I just need to be able to change a simple boolean value stored in a list stored in my viewModel when someone click on my rectangle. Why it is so complicate to do with MVVM?</p>