0

I have a quite complex view with multiple tabs inside tab control. On one tab there is a control with adorner layer. Adorner layer calling CaptureMouse in MouseLeftButtonDown event handler to capture mouse input. Everything works fine.

But if I switch tabs on the view in particular order and then click on adorner layer it fails to capture mouse input: CaptureMouse() returns false. The same time Mouse.Captured returns null. Control that hosts adorner layer continues to work fine and even able to capture mouse.

Can't provide any code because there are many custom controls in action. In simplified layouts everything works fine.

Any suggestions why CaptureMouse may fail?

Seldon
  • 1,395
  • 1
  • 11
  • 19

2 Answers2

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.

ElderMael
  • 7,000
  • 5
  • 34
  • 53
user1834059
  • 502
  • 6
  • 16
2

Make sure that in the MouseLeftButtonUp event handler you're calling ReleaseMouseCapture() otherwise your original adornerlayer will hold on to it.

Also check to ensure that you don't have any controls further up the chain that are also capturing the mouse (you can set handled to true in your adorner layer to prevent that)

Edit: Also make sure IsEnabled is true.

user704772
  • 309
  • 2
  • 11