title: Communication between ViewModel and UserControl's view
body: <p>I working on WPF MVVM project. I'm struggling with communication between viewmodel of my <code>MainWindow</code> and view of <code>usercontrol</code>, placed inside <code>MainWindow</code>.</p>
  
  <p>So I have:</p>
  
  <ul>
  <li><p>UserControl</p></li>
  <li><p>MainWindow</p></li>
  <li><p>MainWindowViewModel</p></li>
  </ul>
  
  <p>My <strong>UserControl</strong> is very simple:</p>
  
  <pre><code>&lt;Grid MouseDown="UIElement_OnMouseDown"&gt;
      &lt;Rectangle Fill="BlueViolet" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>with code-behind (just rise an event when rectangle is clicked, and pass coordinates):</p>
  
  <pre><code>public partial class FooUserControl : UserControl
  {
      public FooUserControl()
      {
          InitializeComponent();
      }
  
      public event EventHandler&lt;BarEventArgs&gt; BarClick;
      private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
      {
          double x = e.GetPosition(this).X;
          double y = e.GetPosition(this).Y;
          string value_to_pass = "[" + x + "," + y + "]";
  
          BarEventArgs bar = new BarEventArgs() { Bar = 2, Foo = value_to_pass };
          BarClick?.Invoke(sender, bar);
      }
  }
  </code></pre>
  
  <p>My <strong>MainWindow</strong> doesn't have code-behind. Just xaml. As you can see I pass click event via Command to <strong>MainWindowViewModel</strong>:</p>
  
  <pre><code>&lt;Window.DataContext&gt;
      &lt;viewModels:MainWindowViewModel /&gt;
  &lt;/Window.DataContext&gt;
  &lt;Grid&gt;
      &lt;local:FooUserControl&gt;
          &lt;i:Interaction.Triggers&gt;
              &lt;i:EventTrigger EventName="BarClick"&gt;
                  &lt;cmd:EventToCommand Command="{Binding ClickedCommand}" PassEventArgsToCommand="True" /&gt;
              &lt;/i:EventTrigger&gt;
          &lt;/i:Interaction.Triggers&gt;
      &lt;/local:FooUserControl&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>and finally my <strong>MainWindowViewModel</strong> has just this command:</p>
  
  <pre><code>public class MainWindowViewModel : ObservableObject
  {
      public ICommand ClickedCommand =&gt; new RelayCommand&lt;BarEventArgs&gt;(o =&gt; Clicked(o.Foo));
      private void Clicked(string a)
      {
          Debug.WriteLine("Clicked " + a);
      }
  }
  </code></pre>
  
  <p>So, communication from UserControl's view to MainWindow's viewmodel, via command, works great. But, <strong>how can I communicate in opposite way? From MainWindowViewModel to UserControl's view?</strong></p>