I created a borderless window in WPF. My goal is to have a window with full functionality.
Currently I have one function remaining.
When the windowState
is Maximized and I click on the titlebar
, the window is set to minimized. This behavior is wrong because the windowState should not minimized unless I double click or if I click or move the cursor.
This is the code I want to only execute if the cursor is moving: (Around 10px from the start position)
private void OnDragMoveWindow(Object sender, MouseButtonEventArgs e)
{
if (this.InternalWindowState == WindowState.Maximized)
{
if (_enableDrag)
{
var c = System.Windows.Forms.Cursor.Position;
this.InternalWindowState = WindowState.Normal;
this.Height = _location.Height;
this.Width = _location.Width;
this.Top = c.Y - (titleBar.ActualHeight / 2);
this.Left = c.X - (_location.Width / 2);
this.DragMove();
}
}
else
{
this.DragMove();
}
}
When I double click this code is executed:
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
private void OnMaximizeWindow(Object sender, MouseButtonEventArgs e)
{
if (this.InternalWindowState == WindowState.Maximized)
this.InternalWindowState = WindowState.Normal;
else
{
timer.Interval = 100;
timer.Tick += timer_Tick;
timer.Start();
_enableDrag = false;
this.InternalWindowState = WindowState.Maximized;
}
}
This question is very confusing, but if you want detect drag actions then you need to compare mouse position between mouse down, and mouse up.
You can override UIElement.OnPreviewMouseLeftButtonDown and UIElement.OnPreviewMouseLeftButtonUp to capture the mouse movement during the click.