Debugging CaptureMouse and Focus
Hi,
I'm doing some refactoring in my code and I'm facing a weird problem. What I want to have is a drag'n drop behaviour. I've basically followed what you did in your sample.
I had a Control deriving from Border, put it into the UIElement tree by declaring it in the Xaml part. Its purpose was basically to move within its parent Canvas and display some representation, capture the mouse on drag and receive move and button up events. It worked great.
Now, rather than declaring it in Xaml, I'm adding it to the parent Canvas's children through C++. But as soon as I've done that, the CaptureMouse method does not work anymore, returning false.
Is there a way for me to check what actually failed? Do you have an idea?
Many thanks,
Alexandre.
I'm doing some refactoring in my code and I'm facing a weird problem. What I want to have is a drag'n drop behaviour. I've basically followed what you did in your sample.
I had a Control deriving from Border, put it into the UIElement tree by declaring it in the Xaml part. Its purpose was basically to move within its parent Canvas and display some representation, capture the mouse on drag and receive move and button up events. It worked great.
Now, rather than declaring it in Xaml, I'm adding it to the parent Canvas's children through C++. But as soon as I've done that, the CaptureMouse method does not work anymore, returning false.
Is there a way for me to check what actually failed? Do you have an idea?
Many thanks,
Alexandre.
Last edited by ZanAlex on 16 Sep 2015, 10:56, edited 1 time in total.
-
sfernandez
Site Admin
- Posts: 3188
- Joined:
Re: Debugging CaptureMouse and Focus
Hi Alex,
Mouse capture can only return false in one of the following situations:
1.- If you try to capture a null element: mouse->Capture(0). But I think you are using the UIElement.CaptureMouse() method, so this is not the case.
2.- If you try to capture an element that is disabled (IsEnabled==False), or is not visible (Visibility!=Visible, or any ancestor is not visible too), or when is not visible for hit testing (IsHitTestVisible==False).
If none of the above is true, then Capture always return true.
Does this information shed some light?
Mouse capture can only return false in one of the following situations:
1.- If you try to capture a null element: mouse->Capture(0). But I think you are using the UIElement.CaptureMouse() method, so this is not the case.
2.- If you try to capture an element that is disabled (IsEnabled==False), or is not visible (Visibility!=Visible, or any ancestor is not visible too), or when is not visible for hit testing (IsHitTestVisible==False).
If none of the above is true, then Capture always return true.
Does this information shed some light?
Re: Debugging CaptureMouse and Focus
Yes it does, thank you very much for your answer!