Wilson
Wilson

Reputation: 8768

Dragging with a customized window

I have a WPF window, without the default windows 'chrome.'

<Window x:Class="Genesis.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Genesis (Alpha)" Height="812" Width="917" Loaded="Window_Loaded"
    DataContext="{Binding RelativeSource={RelativeSource Self}}" Name="Genesis" Closing="Genesis_Closing"
    WindowStyle="None" BorderThickness="0" Margin="0" ShowInTaskbar="False" AllowsTransparency="True" Background="#F8F8F8"></Window>

Since the default bar used for dragging the window is not there, I can't drag the window. How can I recreate the dragging with a new control?

Upvotes: 0

Views: 89

Answers (1)

Mark Hall
Mark Hall

Reputation: 54532

You need to use the Window.DragMove Method.

From above link:

Allows a window to be dragged by a mouse with its left button down over an exposed area of the window's client area.

Something like this:

private void Genesis_MouseDown(object sender, MouseButtonEventArgs e)
{
    if (Mouse.LeftButton == MouseButtonState.Pressed )
        this.DragMove();
}

Upvotes: 2

Related Questions