2 files changed
+83
-4
No files matched your search
@@ -1,7 +1,64 @@
|
|||||||
namespace HandyControl.Controls
|
using System.Windows;
|
||||||
{
|
using System.Windows.Input;
|
||||||
public class Sprite : System.Windows.Window
|
|
||||||
{
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||||
|
|
||||||
|
<Style TargetType="controls:Sprite">
|
||||||
|
<Setter Property="controls:WindowAttach.IgnoreAltF4" Value="True"/>
|
||||||
|
<Setter Property="controls:WindowAttach.ShowInTaskManager" Value="False"/>
|
||||||
|
<Setter Property="SizeToContent" Value="WidthAndHeight"/>
|
||||||
|
<Setter Property="ResizeMode" Value="NoResize"/>
|
||||||
|
<Setter Property="Background" Value="Transparent"/>
|
||||||
|
<Setter Property="ShowActivated" Value="False"/>
|
||||||
|
<Setter Property="ShowInTaskbar" Value="False"/>
|
||||||
|
<Setter Property="Topmost" Value="True"/>
|
||||||
|
<Setter Property="Template">
|
||||||
|
<Setter.Value>
|
||||||
|
<ControlTemplate TargetType="controls:Sprite">
|
||||||
|
<ContentPresenter Margin="{TemplateBinding Padding}" controls:WindowAttach.IsDragElement="True" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
</ResourceDictionary>
|
||||||
Reference in new issue
Block a user