Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
355
Drag drop in canvas within splitpane
posted

I have a canvas within a DocumentContentHost within a SplitPane.  I am dragging and dropping objects within the canvas.  it all works fine... but, i want to cancel the drag whenever the object is dragged out of the bounds of the canvas.  I have tried to use the previewdragleave event on the canvas, but, it doesn't seem to fire.  So, I am trying to cancel the drag within the PreviewMouseMove event.

So, how do i get the "bounds" of the SplitPane that the canvas is a child of?  I have tried variations of this:

bounds = VisualTreeHelper.GetDescendantBounds(xamMainDockMgr.ActivePane) and the Left and Top properties (x,y) are always 0,0.  The Right property is the actualwidth and the Bottom property is the actualheight.  Bascially, I have tried using the VisualTreeHelper with all of the container objects within my xamDockManager and they all seem to return the same.  I also get the same whenever i try to use the Canvas.GetLeft method.  I realize the canvas is a child and would be considered at 0,0 within the parent, but, why are all the parent(s) also returning 0,0?

I will need to be able to capture the boundaries at runtime since the user can move (unpin, etc) the docked panel.  Any ideas?  it must be something easy i am just missing it.

Parents
  • 54937
    Verified Answer
    Offline posted

    As documented in MS' help, GetDescendantBounds is just going to union all the rects of the descendants and the rect returned will be relative to the reference element. As for Canvas.Left, that is just an attached property defined by the Canvas class that it uses to know where to position its direct children - it would only have values that you set on an element.

    I'm not quite sure I follow what rect (and relative to what element) you are looking for but in WPF if you want to get a rect/point relative to another element then you would use the TransformToVisual method (or one of the TransformToAncestor|Descendant methods) and then use the Transform(Bounds) methods of that.

Reply Children
No Data