Init commit
This commit is contained in:
45
Infrastructure/MouseBehaviour.cs
Normal file
45
Infrastructure/MouseBehaviour.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interactivity;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public class MouseBehaviour : Behavior<Panel>
|
||||
{
|
||||
public static readonly DependencyProperty MouseYProperty = DependencyProperty.Register(
|
||||
"MouseY", typeof(double), typeof(MouseBehaviour), new PropertyMetadata(default(double)));
|
||||
|
||||
public static readonly DependencyProperty MouseXProperty = DependencyProperty.Register(
|
||||
"MouseX", typeof(double), typeof(MouseBehaviour), new PropertyMetadata(default(double)));
|
||||
|
||||
public double MouseY
|
||||
{
|
||||
get => (double)GetValue(MouseYProperty);
|
||||
set => SetValue(MouseYProperty, value);
|
||||
}
|
||||
|
||||
public double MouseX
|
||||
{
|
||||
get => (double)GetValue(MouseXProperty);
|
||||
set => SetValue(MouseXProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnAttached()
|
||||
{
|
||||
AssociatedObject.MouseMove += AssociatedObjectOnMouseMove;
|
||||
}
|
||||
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
AssociatedObject.MouseMove -= AssociatedObjectOnMouseMove;
|
||||
}
|
||||
|
||||
private void AssociatedObjectOnMouseMove(object sender, MouseEventArgs mouseEventArgs)
|
||||
{
|
||||
var pos = mouseEventArgs.GetPosition(AssociatedObject);
|
||||
MouseX = pos.X;
|
||||
MouseY = pos.Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user