title: Using WPF xaml in MVP-VM Events or button click
body: <p>OK so I am (very) new to WPF but have 13 years with Win-forms, so no newbie. 
  I am writing a new system and decided to break the ice with WPF using the MVP-VM pattern as I am familiar with MVP. </p>
  
  <p>Now I am also reusing my own (composite) architecture which has the UI or presentation layer in a project separate from the Presenters and View models. One of the main benefits to this approach is that the Presenter layer or Base layer has all the presentation/command/controller logic and no reference to UI matters. The Main IDEA is that this layer has no reference to any UI assemblies like Winforms or WPF.</p>
  
  <p>The ISSUE: 
  IN Xaml, I have a menu item 'Exit' which I want to bind to the View model. Every example of this that I have seen uses ICommand.. which is housed in Presentation.core... the view model is in the presentation layer and therefore does not have a reference to the Presentation.Core..</p>
  
  <p>The Xaml thus far is </p>
  
  <pre><code>&lt;Window x:Class="Homestead.Wpf.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow" Height="244" Width="490" xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"&gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="23"/&gt;
          &lt;RowDefinition Height="*"/&gt;
          &lt;RowDefinition Height="23" /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Menu Grid.Row="0"&gt;
          &lt;MenuItem Header="File"&gt;
              &lt;MenuItem Header="Exit"  /&gt;
          &lt;/MenuItem&gt; 
      &lt;/Menu&gt;
      &lt;StatusBar Grid.Row="2"  &gt;
          &lt;StatusBarItem   &gt;
              &lt;TextBlock  Text="{Binding Path=StatusMessage}" /&gt;
          &lt;/StatusBarItem&gt;
          &lt;StatusBarItem  HorizontalAlignment="Right" MinWidth="120"&gt;
              &lt;TextBlock  Text="{Binding Path=UserName}" /&gt;
          &lt;/StatusBarItem&gt;
      &lt;/StatusBar&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>the view model thus far is </p>
  
  <pre><code>public class ShellViewModel : ViewModelBase
  {
  
      #region Private Variables
  
      private string _status = string.Empty;
      private string _userName;
  
      #endregion
  
      #region Public Properties
  
      public string StatusMessage
      {
          get { return _status; }
          set
          {
              _status = value;
              OnPropertyChanged("StatusMessage");
          }
      }
  
      public string UserName
      {
          get { return _userName; }
          set
          {
              _userName = value;
              OnPropertyChanged("UserName");
          }
      }
  
  
      #endregion
  
      #region Commands
  
      // No reference to ICommand... WTF
  
      #endregion
  }
  </code></pre>
  
  <ol>
  <li>is there any alternative to this pattern..(without using code behind)</li>
  <li>How does this work with Menu items added at runtime, amusing there is a way.</li>
  </ol>
  
  <p>Must I redesign or break the design pattern to use WPF? please guide me.</p>
  
  <p>There is one possibility that I can see and that is to Interface out the ViewModel as well as the View.. I have a Controller that creates the Presenters  that usually passes in to the presenter the implementation of the view. I.e a typical Presenter constructor would be </p>
  
  <pre><code>    public ErrorMessagePresenter(IErrorMessageView view)
      {
          View = view;
          View.Presenter = this;            
      }
  </code></pre>
  
  <p>The controller code is thus</p>
  
  <pre><code>    public ErrorMessagePresenter CreateErrorPresenter()
      {
          return new ErrorMessagePresenter(_viewFactory.CreateErrorMessageView());
      }
  </code></pre>
  
  <p>now I know that this is reversed but literally the UI layer is only concerned with UI matters, everything else including navigation is handled in the Base layer or below..</p>