WPF:为什么CaptureMouse会失败?

Sel*_*don 0 wpf adornerlayer mousecapture

我有一个非常复杂的视图,在选项卡控件中有多个选项卡.在一个选项卡上有一个带有装饰层的控件.Adorner层在MouseLeftButtonDown事件处理程序中调用CaptureMouse来捕获鼠标输入.一切正常.

但是,如果我按特定顺序切换视图上的选项卡然后单击adorner图层则无法捕获鼠标输入:CaptureMouse()返回false.同时Mouse.Captured返回null.托管装配层的控件继续正常工作,甚至能够捕获鼠标.

无法提供任何代码,因为有许多自定义控件在运行.在简化的布局中,一切正常.

任何有关CaptureMouse失败的建议?

use*_*059 5

If the IInputElement is a UIElement or a UIElement3D, IsVisible and IsEnabled must be true.

If the IInputElement is a ContentElement, there is no IsVisible so just IsEnabled must be true. This is of course at the time you call Mouse.Capture. Also, the PresentationSource for the IInputElement's containing visual must have an IMouseInputProvider.

I think the problem here is either another element immediately taking capture, or IsVisible being false at the time you call Capture.