title: AppBarButton Command in MVVM does not Trigger RelayCommand
body: <p>I have Windows Phone Class Library that uses the MVVM model. In my <code>Generic.xaml</code> I have the Style for my <code>CustomElementControl.cs</code> that has a <code>CustomElementViewModel.cs</code>. I also have a <code>ViewModelLocator.cs</code> that relates ViewModels to Controls that is named in this context as Locator, but that is not relevant to this case. Now, if I add a Command to a Button like so:</p>
  
  <pre><code>&lt;Style TargetType="view:CustomElementControl"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="view:CustomElementControl"&gt;
                  &lt;Page x:Name="pageRoot" DataContext="{Binding Source={StaticResource Locator}, Path=view:CustomElementViewModel, Mode=TwoWay}"&gt;
                      &lt;TextBlock Text="something" Foreground="{Binding Path=ColorTest}" /&gt;
                      &lt;Button Content="MyButton" Command="{Binding MultiSelectCommand}" /&gt;
                  &lt;/Page&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>And catch in the <code>CustomElementViewModel.cs</code> like so:</p>
  
  <pre><code>private RelayCommand _multiSelectCommand;
  public RelayCommand MultiSelectCommand {
      get {
          if(_multiSelectCommand == null) {
              _multiSelectCommand = new RelayCommand(
              () =&gt; {
                  this.SelectionMode = (this.SelectionMode == ListViewSelectionMode.Single) ? ListViewSelectionMode.Multiple : ListViewSelectionMode.Single;
              });
          }
          return _multiSelectCommand;
      }
  }
  </code></pre>
  
  <p>It works fine, however, if I want to add the Command event to an AppBarButton like so:</p>
  
  <pre><code>&lt;Style TargetType="viewCustomElementControl"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="view:CustomElementControl"&gt;
                  &lt;Page x:Name="pageRoot" DataContext="{Binding Source={StaticResource Locator}, Path=view:CustomElementViewModel, Mode=TwoWay}"&gt;
                          &lt;TextBlock Text="something" Foreground="{Binding Path=ColorTest}" /&gt;
                      &lt;/Page&gt;
                      &lt;Page.BottomAppBar&gt;
                          &lt;CommandBar&gt;
                              &lt;AppBarButton Icon="AllApps" Label="multiselect" Command="{Binding MultiSelectCommand}" /&gt;
                          &lt;/CommandBar&gt;
                      &lt;/Page.BottomAppBar&gt;
                  &lt;/Page&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>The RelayCommand is never triggered. What am I missing here?</p>
  
  <p><br><br>
  <b>UPDATE</b><br>
  I've even tried setting the DataContext of the AppBarButton like so:</p>
  
  <pre><code>&lt;AppBarButton Icon="AllApps" Label="multiselect" Command="{Binding DataContext.MultiSelectCommand, ElementName=pageRoot, Mode=OneWay}" /&gt;
  </code></pre>
  
  <p>And</p>
  
  <pre><code>&lt;AppBarButton Icon="AllApps" Label="multiselect" DataContext="{Binding Source={StaticResource Locator}, Path=CustomElementViewModel, Mode=TwoWay} Command="{Binding MultiSelectCommand}" /&gt;
  </code></pre>
  
  <p>And none works.
  <br><br>
  <b>UPDATE 2</b><br>
  Here's a sample: <a href="http://1drv.ms/1vRnaYH" rel="nofollow">http://1drv.ms/1vRnaYH</a></p>