Offset Tree Drag Cue from Mouse Cursor

4 posts, 0 answers
  1. TONY
    TONY avatar
    4 posts
    Member since:
    Aug 2011

    Posted 04 Nov 2011 Link to this post

    Hello,

    Is there a way to offset the Tree Drag Cue visual? I need a clear view of the drop target and depending on how the drag was started, the drag cue obscures the target.

    I would like to have the cue sitting adjacent to the mouse cursor, where the cue is not behind the mouse cursor at all.

    Thanks
    Tony.
  2. TONY
    TONY avatar
    4 posts
    Member since:
    Aug 2011

    Posted 04 Nov 2011 Link to this post

    Figured this out this way:

    Made some extension methods to get the relative (to the cue) mouse coordinates and then offset the cue with a Thickness as a margin. Seems like the cue needs to render before an effective transform can be used.

    public static Point ToCueCoordinates( this TreeViewDragCue cue, Point appCoords )
    {
        // need try-catch if cue is not rendered yet
        GeneralTransform pToChild = Application.Current.RootVisual.TransformToVisual( cue );
        return( pToChild.Transform( appCoords );
    }
     
    public static void OffsetCue( this TreeViewDragCue cue, Point appCoords, double relX, double relY )
    {
        ThreadPool.QueueUserWorkItem( (state) =>
        {
            Thread.Sleep( 300 ); // ensure drawn
            Deployment.Current.Dispatcher.BeginInvoke( ( )=>
            {
                Point p = cue.ToCueCoordinates( appCoords );
                cue.Margin = new Thickness( p + relX, p + relY, 0, 0 );
            } );
        });
    }
    }
  3. DevCraft banner
  4. TONY
    TONY avatar
    4 posts
    Member since:
    Aug 2011

    Posted 04 Nov 2011 Link to this post

    The above solution doesn't work very consistently.

    It would be much easier if there was a way to position the visual cue as part of the DnD args.
  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 09 Nov 2011 Link to this post

    Hello Tony,

    You can change the DragCue offset by handling the OnDragInitialized() event and changing the DragVisualOffset. I attached a sample to get you started. Let me know if it helps.

    Best wishes,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top