title: How to build my own close button?
body: <p>I have a wpf application with a MVVM. I am trying here to build my own close button. Based on this answer <a href="https://stackoverflow.com/questions/5193763/creating-a-custom-close-button-in-wpf"><strong>Creating a custom Close Button in WPF</strong></a> I added a button event handler in the <em>View</em>(xaml.cs) code. However, it is not recognizing the <code>Close();</code> call (doesn't exist in the context - <em>Can't resolve symbol</em>). </p>
  
  <p>Also I tried the other answer and added <code>Command</code> and <code>CommandParameter</code> into my button's xaml. But the function behind is not getting hits. In <a href="https://stackoverflow.com/questions/1065887/how-to-bind-close-command-to-a-button"><strong>How to bind Close command to a button</strong></a> using the <code>RelayCommand</code> also my wpf is not recognizing <code>RelayCommand</code>. Then <a href="https://stackoverflow.com/questions/862570/how-can-i-use-the-relaycommand-in-wpf"><strong>How can I use the RelayCommand in wpf</strong></a> said that I have to write it myself(really?). I remember there was a simple way similar to just <em>set an event handler for the button and call <code>Close();</code></em>. But, how can I do that or why it is not working for me? </p>
  
  <p>View code:</p>
  
  <pre><code>private void closeButton_Click(object sender, RoutedEventArgs e)
  {
      // I want to call close the whole app on button click
      //Close(); is not recognized
  }
  
  private void performMainCloseButtonCommand(object Parameter)
  {
      // This doesn't get hits on button click
      Window objWindow = Parameter as Window;
      objWindow.Close();
  }
  </code></pre>
  
  <p>Button XAML: </p>
  
  <pre><code>        &lt;Button x:Name="closeButton" RenderTransformOrigin="0.5,0.5" Padding="0" Margin="701,0,0,0" BorderThickness="0" Click="closeButton_Click" Command="{Binding MainCloseButtonCommand}" CommandParameter="{Binding ElementName = mainWindow}" Height="45" Width="45" &gt;
              &lt;StackPanel Height="45" Width="45"&gt;
                  &lt;Image x:Name="closeButtonImage" Margin="0" Source="/ProjectName;component/Resources/x.fw.png" Height="33"/&gt;
                  &lt;TextBlock Text="Close" Width="36" Padding="6,0,0,0" HorizontalAlignment="Center" Height="13" FontSize="10"/&gt;
              &lt;/StackPanel&gt;
          &lt;/Button&gt;
  </code></pre>