Reputation: 10039
I have a control in my application that needs to know when any other control in the visual tree captures the mouse.
Is this possible?
Upvotes: 1
Views: 554
Reputation: 17848
Use the Mouse.GotMouseCapture attached event.
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
static MainWindow() {
EventManager.RegisterClassHandler(typeof(UIElement), Mouse.GotMouseCaptureEvent, new MouseEventHandler(MainWindow_GotMouseCapture));
}
static void MainWindow_GotMouseCapture(object sender, MouseEventArgs e) {
// e.OriginalSource is a captured element
}
}
Note, that the captured element is available via the Mouse.Captured static property.
Upvotes: 2