forked from LionelJouin/PiP-Tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added minimize button and disable aero snap
- Loading branch information
Showing
5 changed files
with
199 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Interactivity; | ||
|
||
namespace PiP_Tool.Controls | ||
{/// <summary> | ||
/// behavior that makes a window/dialog draggable by clicking anywhere | ||
/// on it that is not a control (ie, button) | ||
/// </summary> | ||
/// https://stackoverflow.com/questions/2470685/how-do-you-disable-aero-snap-in-an-application/13403067#13403067 | ||
public class DragMoveBehavior<T> : Behavior<T> where T : FrameworkElement | ||
{ | ||
protected override void OnAttached() | ||
{ | ||
AssociatedObject.MouseLeftButtonDown += MouseDown; | ||
base.OnAttached(); | ||
} | ||
|
||
protected override void OnDetaching() | ||
{ | ||
AssociatedObject.MouseLeftButtonDown -= MouseDown; | ||
base.OnDetaching(); | ||
} | ||
|
||
void MouseDown(object sender, EventArgs ea) => Window.GetWindow(sender as T)?.DragMove(); | ||
} | ||
|
||
public class WinDragMoveBehavior : DragMoveBehavior<Window> { } | ||
|
||
public class UCDragMoveBehavior : DragMoveBehavior<UserControl> { } | ||
|
||
/// <summary> | ||
/// behavior that makes a window/dialog not resizable while clicked. this prevents | ||
/// the window from being snapped to the edge of the screen (AeroSnap). if DragMoveBehavior | ||
/// is also used, this must be attached first. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
public class NoSnapBehavior<T> : Behavior<T> where T : FrameworkElement | ||
{ | ||
ResizeMode lastMode = ResizeMode.NoResize; | ||
protected override void OnAttached() | ||
{ | ||
AssociatedObject.MouseLeftButtonDown += MouseDown; | ||
AssociatedObject.MouseLeftButtonUp += MouseUp; | ||
base.OnAttached(); | ||
} | ||
|
||
protected override void OnDetaching() | ||
{ | ||
AssociatedObject.MouseLeftButtonDown -= MouseDown; | ||
AssociatedObject.MouseLeftButtonUp -= MouseUp; | ||
base.OnDetaching(); | ||
} | ||
|
||
/// <summary> | ||
/// make it so the window can be moved by dragging | ||
/// </summary> | ||
void MouseDown(object sender, EventArgs ea) | ||
{ | ||
var win = Window.GetWindow(sender as T); | ||
if (win != null && win.ResizeMode != ResizeMode.NoResize) | ||
{ | ||
lastMode = win.ResizeMode; | ||
win.ResizeMode = ResizeMode.NoResize; | ||
win.UpdateLayout(); | ||
} | ||
} | ||
|
||
void MouseUp(object sender, EventArgs ea) | ||
{ | ||
var win = Window.GetWindow(sender as T); | ||
if (win != null && win.ResizeMode != lastMode) | ||
{ | ||
win.ResizeMode = lastMode; | ||
win.UpdateLayout(); | ||
} | ||
} | ||
} | ||
|
||
public class WinNoSnapBehavior : NoSnapBehavior<Window> { } | ||
|
||
public class UCNoSnapBehavior : NoSnapBehavior<UserControl> { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters