This is a migrated thread and some comments may be shown as answers.

Offset Tree Drag Cue from Mouse Cursor

3 Answers 77 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
TONY
Top achievements
Rank 1
TONY asked on 04 Nov 2011, 04:26 PM
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.

3 Answers, 1 is accepted

Sort by
0
TONY
Top achievements
Rank 1
answered on 04 Nov 2011, 06:25 PM
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 );
        } );
    });
}
}
0
TONY
Top achievements
Rank 1
answered on 04 Nov 2011, 07:49 PM
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.
0
Tina Stancheva
Telerik team
answered on 09 Nov 2011, 03:28 PM
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 >>

Tags
TreeView
Asked by
TONY
Top achievements
Rank 1
Answers by
TONY
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or