title: Is send command from ViewModel to View violating MVVM?
body: <p>I want my <code>DataGrid</code> scroll to bottom as new item added to underlying <code>ObservableCollection</code>. To achieve this, I make an interface similar to <code>ICommand</code> but in "reverse" way.</p>
  
  <pre><code>public interface IViewModelCommand
  {
      void Execute(object parameter);
  }
  </code></pre>
  
  <p>Implementation</p>
  
  <pre><code>public class ViewModelRelayCommand : IViewModelCommand
  {
      private readonly Action&lt;object&gt; _action;
      public ViewModelRelayCommand(Action&lt;object&gt; action)
      {
          if(action == null)
              throw new ArgumentNullException("action");
  
          _action = action;
      }
  
      public void Execute(object parameter)
      {
          _action(parameter);
      }
  }
  </code></pre>
  
  <p>My ViewModel</p>
  
  <pre><code>    private IViewModelCommand _scrollAction;
      public IViewModelCommand ScrollAction
      {
          get { return _scrollAction; }
          set
          {
              if (_scrollAction == value)
                  return;
              _scrollAction = value;OnPropertyChanged();
          }
      }
  </code></pre>
  
  <p>Then I create behavior for my DataGrid.
  (Scroll to end code taken from <a href="https://stackoverflow.com/questions/1027051/how-to-autoscroll-on-wpf-datagrid">here</a>)</p>
  
  <pre><code>public sealed class DataGridBehavior : Behavior&lt;DataGrid&gt;
  {
          public static readonly DependencyProperty ScrollToEndProperty =
              DependencyProperty.Register (
                  "ScrollToEnd",
                  typeof(IViewModelCommand),
                  typeof(DataGridBehavior),
                  new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.None)
              );
  
          public IViewModelCommand ScrollToEnd
          {
              get { return (IViewModelCommand)GetValue(ScrollToEndProperty); }
              set { SetValue(ScrollToEndProperty, value); }
          }
  
          protected override void OnAttached()
          {
              base.OnAttached();
              ScrollToEnd = new ViewModelRelayCommand(Scroll);
          }
  
          protected override void OnDetaching()
          {
              base.OnDetaching();
              ScrollToEnd = null;
          }
  
          private void Scroll(object parameter)
          {
              var mainDataGrid = AssociatedObject;
              if (mainDataGrid.Items.Count &gt; 0)
              {
                  var border = VisualTreeHelper.GetChild(mainDataGrid, 0) as Decorator;
                  if (border != null)
                  {
                      var scroll = border.Child as ScrollViewer;
                      if (scroll != null) scroll.ScrollToEnd();
                  }
              }
          }
      }
  </code></pre>
  
  <p>And attach it to my DataGrid</p>
  
  <pre><code>        &lt;i:Interaction.Behaviors&gt;
              &lt;local:DataGridBehavior ScrollToEnd="{Binding ScrollAction, Mode=OneWayToSource}" /&gt;
          &lt;/i:Interaction.Behaviors&gt;
  </code></pre>
  
  <p>Then from my ViewModel I just call <code>if (_scrollAction != null) _scrollAction.Execute(null);</code> to scroll my grid and it works very well.</p>
  
  <p>My question, is this violating MVVM?</p>