The WPF program below puts up a window which looks like this:
Mouse-movement outside the black square causes the window title to be updated with the mouse's position. The updating stops when the mouse enters the square.
I'd like for MouseMove to continue to trigger even when the mouse is over the square. Is there a way to do this?
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Wpf_Particle_Demo
{
class DrawingVisualElement : FrameworkElement
{
public DrawingVisual visual;
public DrawingVisualElement() { visual = new DrawingVisual(); }
protected override int VisualChildrenCount { get { return 1; } }
protected override Visual GetVisualChild(int index) { return visual; }
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var canvas = new Canvas();
Content = canvas;
var element = new DrawingVisualElement();
canvas.Children.Add(element);
CompositionTarget.Rendering += (s, e) =>
{
using (var dc = element.visual.RenderOpen())
dc.DrawRectangle(Brushes.Black, null, new Rect(0, 0, 50, 50));
};
MouseMove += (s, e) => Title = e.GetPosition(canvas).ToString();
}
}
}