title: MVVM and events
body: <p>To keep code out of the view when using the Model-View-View Model pattern (aka Presentation Model), I can expose commands as properties in the view model and bind to those commands from the view. This way my views can be entirely written XAML and no code-behind, other than the mandatory constructor call to <code>InitializeComponent()</code>.</p>
  
  <p>This works well for controls that implement <code>ICommandSource</code> . But what if I want to run some action when the text of a textbox changes? The compiler refuses XAML where I set attach an handler that is not on the code-behind file to an event.</p>
  
  <p>I can write some event handlers that simply run commands (or methods) in the view model, like this:</p>
  
  <pre><code>private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  {
      ((EditPersonViewModel) DataContext).ChangeBioCommand.Execute(e.Changes);
  }
  </code></pre>
  
  <p>This works, but I don't like the fact I have to write such ugly boilerplate code all over my views. Is there a better solution?</p>