title: MVVM Light RelayCommand binding not working in user control
body: <p>I'm working on a WPF application which uses the MVVM Light toolkit. I'm creating a wizard and I want to show buttons for navigating to the previous step and the next step on every page. In order to avoid code duplication, I use a user control which provides the buttons.</p>
  
  <p>I'm trying to bind the next button's <code>Command</code> property to a dependency property , which is defined in the code behind file, called <code>NextStepCommand</code>. The type of this property is <code>RelayCommand</code>. The user control's dependency property <code>NextStepCommand</code> should then be bound to the window's property with the exact same name <code>NextStepCommand</code>; of course it also is of type <code>RelayCommand</code>.</p>
  
  <p>However, the binding from the window's property <code>NextStepCommand</code> to the button's property <code>Command</code> doesn't work. Binding the window's property <code>NextStepCommand</code> to an arbitrary button defined in the window's XAML file works fine; so does implementing a <code>RelayCommand</code> in the user control's code behind class and binding it to the next button defined in the user control. Nevertheless, the full link from the window's property to the user control's button does not work and I can't figure out a solution.</p>
  
  <p>The user control's XAML code is shown below.</p>
  
  <pre><code>&lt;UserControl DataContext="{Binding RelativeSource={RelativeSource Self}}"&gt; 
      &lt;DockPanel&gt;
          &lt;Button DockPanel.Dock="Left"
                  IsEnabled="{Binding Path=PreviousStepEnabled}"
                  Command="{Binding Path=PreviousStepCommand}"&gt;Back&lt;/Button&gt;
          &lt;Button DockPanel.Dock="Right"
                  IsEnabled="{Binding Path=NextStepEnabled}"
                  Command="{Binding Path=NextStepCommand, Mode=OneWay}"&gt;Next&lt;/Button&gt;
          &lt;Label/&gt;
      &lt;/DockPanel&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>The user control's <code>NextStepCommand</code> is defined the following way:</p>
  
  <pre><code>public RelayCommand NextStepCommand
  {
      get { return (RelayCommand)GetValue(NextStepCommandProperty); }
      set { SetValue(NextStepCommandProperty, value); }
  }
  
  public static readonly DependencyProperty NextStepCommandProperty =
      DependencyProperty.Register(nameof(NextStepCommand), typeof(RelayCommand), typeof(WizardStepSwitchBar), new PropertyMetadata(default(RelayCommand)));
  </code></pre>
  
  <p>The window's XAML is displayed below.</p>
  
  <pre><code>&lt;MahApps:MetroWindow
       xmlns:MahApps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
       DataContext="{Binding Source={StaticResource Locator}, Path=BasicSettings}"&gt;
      &lt;Grid Style="{StaticResource MainContainerMargin}"&gt;
          &lt;control:WizardStepSwitchBar Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" PreviousStepEnabled="False" NextStepCommand="{Binding Path=NextStepCommand, Mode=OneWay}"/&gt;
      &lt;/Grid&gt;
  &lt;/MahApps:MetroWindow&gt;
  </code></pre>
  
  <p>The implementation of the window's <code>NextStepCommand</code> property is quite simple:</p>
  
  <pre><code>public RelayCommand NextStepCommand
  {
      get
      {
          return new RelayCommand(this.OnNextStep);
      }
  }
  
  private void OnNextStep()
  {
      MessageBox.Show("It works!");
  }
  </code></pre>
  
  <p>I tried using <a href="https://stackoverflow.com/a/39484717/4408431">this answer</a>, but didn't provide a solution to my issue. Thank you in advance for your support!</p>