Double-click event on WPF Window border

Here is one way.. Just set your Window.WindowStyle to "None" and create your down window border:

<Grid>
    <Border 
        BorderBrush="Silver"  
        BorderThickness="10" 
        Name="border1" 
        MouseLeftButtonDown="border1_MouseLeftButtonDown" />
</Grid>

In code behind:

private void border1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    if (e.ClickCount == 2)
       MessageBox.Show("Double Click");
}

Sorry for being late to the party, but I'd like to suggest that you're better off with the first answer (by Jaster) to Why doesnt WPF border control have a mousedoubleclick event?.

It's way more cleaner and doesn't even use one single line of code behind, hence it's fully MVVM-compliant and should be your way to go.

<Window x:Class="Yoda.Frontend.MainView" x:Name="MainViewWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Border>
    <Border.InputBindings>
      <MouseBinding MouseAction="LeftDoubleClick"
                    Command="{Binding YourBindableCommand}"
                    CommandParameter="{Binding}" />
    </Border.InputBindings>
  </Border>
</Window>

Note: Of course, you have to replace YourBindableCommand with the appropriate command, probably provided by your ViewModel. If you need help on that, just let me know.

Tags:

C#

.Net

Wpf