Merge branch 'master' of https://github.com/HandyOrg/HandyControl into upstream-master

This commit is contained in:
noctwolf committed 2019-08-15 23:06:29 +08:00
commit 2f34bb72d6
53 files changed
+775 -69

No files matched your search

@@ -0,0 +1,64 @@
using System.Windows;
using System.Windows.Input;
namespace HandyControl.Controls
{
public sealed class Sprite : System.Windows.Window
{
private bool _isLeftButtonPressed;
private double _leftMax;
private double _topMax;
private Sprite()
{
WindowStyle = WindowStyle.None;
AllowsTransparency = true;
InputManager.Current.PostProcessInput += Current_PostProcessInput;
}
private void Current_PostProcessInput(object sender, ProcessInputEventArgs e)
{
if (Mouse.LeftButton == MouseButtonState.Pressed)
{
_isLeftButtonPressed = true;
}
else if(_isLeftButtonPressed)
{
if (Left < 0)
{
Left = 0;
}
if (Left > _leftMax)
{
Left = _leftMax;
}
if (Top > _topMax)
{
Top = _topMax;
}
}
}
public static Sprite Show(object content)
{
var sprite = new Sprite
{
Content = content
};
sprite.Show();
var desktopWorkingArea = SystemParameters.WorkArea;
sprite._leftMax = desktopWorkingArea.Width - sprite.ActualWidth;
sprite._topMax = desktopWorkingArea.Height - sprite.ActualHeight;
sprite.Left = sprite._leftMax - 50;
sprite.Top = 50 - sprite.Padding.Top;
return sprite;
}
}
}