2011-11-10 23 views

回答

2

使用Mouse.GotMouseCapture附加事件。

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 
    } 
} 

請注意,捕獲的元素通過Mouse.Captured static屬性可用。

+0

非常感謝您的回答。雖然我還不確定我是否可以使用它。想要知道鼠標是否被捕獲的控件在可視化樹中深處,並且無法在如此高的級別註冊事件處理程序。 –

+0

我明白你的意思,你根本沒有使用MainWindow來註冊事件。所以也許這是我需要的答案,我會再看一遍。 –

+0

有什麼辦法可以取消註冊類處理程序? –

相關問題