title: Replicating standard system menu with WindowChrome?
body: <p>When using <a href="http://msdn.microsoft.com/en-us/library/microsoft.windows.shell.windowchrome.aspx" rel="nofollow">WindowChrome</a> (<a href="http://archive.msdn.microsoft.com/WPFShell/Release/ProjectReleases.aspx?ReleaseId=4332" rel="nofollow">downloadable here</a>) to customize the nonclient area of a window, a natural starting point is to make a title bar that looks and acts identical to a standard title bar. This requires adding a "fake" application icon and title bar, because apparently WindowChrome disables those features (the minimize, maximize and close buttons still work.)</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>&lt;Window x:Class="MyApp.MainWindow"
          x:Name="MainWindowItself"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell"
          xmlns:local="clr-namespace:MyApp"
          Title="My Application" Icon="App.ico" Height="350" Width="525"&gt;
      &lt;Window.Resources&gt;
          &lt;Style TargetType="{x:Type local:MainWindow}"&gt;
              &lt;Setter Property="shell:WindowChrome.WindowChrome"&gt;
                  &lt;Setter.Value&gt;
                      &lt;shell:WindowChrome /&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
              &lt;Setter Property="Template"&gt;
                  &lt;Setter.Value&gt;
                      &lt;ControlTemplate TargetType="{x:Type local:MainWindow}"&gt;
                          &lt;Grid&gt;
                              &lt;Border Background="White" Margin="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowNonClientFrameThickness}"&gt;
                                  &lt;ContentPresenter Content="{TemplateBinding Content}" /&gt;
                              &lt;/Border&gt;
                              &lt;TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" 
                                 VerticalAlignment="Top" HorizontalAlignment="Left" 
                                 Margin="32,8,0,0"/&gt;
                              &lt;Image x:Name="SystemMenuIcon" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon}"
                                 VerticalAlignment="Top" HorizontalAlignment="Left"
                                 Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness}" 
                                 Width="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=SmallIconSize.Width}"
                                 shell:WindowChrome.IsHitTestVisibleInChrome="True" MouseDown="SystemMenuIcon_MouseDown"&gt;
                              &lt;/Image&gt;
                          &lt;/Grid&gt;
                      &lt;/ControlTemplate&gt;
                  &lt;/Setter.Value&gt;
              &lt;/Setter&gt;
          &lt;/Style&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;TextBlock Text="Client area content goes here"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Code behind:</p>
  
  <pre><code>private void SystemMenuIcon_MouseDown(object sender, MouseButtonEventArgs e)
  {
      var offs = SystemParameters2.Current.WindowNonClientFrameThickness;
      SystemCommands.ShowSystemMenu(this, new Point(Left + offs.Left, Top + offs.Top));
  }
  </code></pre>
  
  <p>This comes very close to working. The first problem is that after you click the application icon and the system menu appears, the menu should disappear if you click a second time--instead, the menu just redraws. Also, if you double-click then the window should close, but Image doesn't have a double-click event. How would you suggest adding these features?</p>