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;
}
}
My Solution is :
The Event Source is MouseDown
Yours is not Working because the mousedoubleclick event is after the mouse click event. So your Window state is switching betwenn the states with one "MouseAction".
Replace my -10 constants with your prefered values.