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

Treeview D&D Tooltip

1 Answer 55 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Stefania
Top achievements
Rank 2
Stefania asked on 27 Sep 2013, 10:47 AM
Hi
I have a draggable treeview and I would like to write on dragvisual content something like "Drop inside <Node Information>".
How can I get the Node information?

I tried something like this but "options" is always null

private Telerik.Windows.Controls.Label dragVisualLabel;
private void OnDragInitialize(object sender, DragInitializeEventArgs args)
{
    this.dragVisualLabel = new Telerik.Windows.Controls.Label() { ContentTemplate = RootGrid.Resources["ItemTemplate"] as DataTemplate, Content = "" };
    args.DragVisual = this.dragVisualLabel;
}
private void OnGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs args)
{
    if (args.Effects == DragDropEffects.Move)
    {
        args.UseDefaultCursors = false;
        args.SetCursor(Cursors.Hand);
 
        var options = DragDropPayloadManager.GetDataFromObject(args.OriginalSource, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
        if (options != null)
        {
            var dragVisual = options.DragVisual as TreeViewDragVisual;
 
            if (dragVisual != null)
            {
                var classModel = (options.DropTargetItem).DataContext as ClassObjectModel;
 
                if (classModel != null)
                {
                    this.dragVisualLabel.Content = string.Format("Drop inside {0} - {1}", classModel.Class.Code, classModel.Class.Description);
                }
            }
        }
 
 
        //  this.dragVisualLabel.Background = new SolidColorBrush(Colors.Yellow);              
 
    }
    else if (args.Effects == DragDropEffects.None)
    {
        args.UseDefaultCursors = false;
        args.SetCursor(Cursors.None);
        // this.dragVisualLabel.Background = new SolidColorBrush(Colors.Red);
    }
    else
    {
        args.UseDefaultCursors = true;
        //  this.dragVisualLabel.Background = new SolidColorBrush(Colors.Green);
    }
 
    args.Handled = true;
}


Thanks

1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 27 Sep 2013, 01:59 PM
Hello Stefania,

The data that you extract from the DragPayload has to be set in the DragInitialize event. Otherwise you cannot extract it. 
Let me try to explain, If you set the e.Data in the DragIntialize method, to a Payload, which has data set with key - "Key", and data - "Data", you can later extract it by using the same key. You cannot get data that hasn't been set. 

As to finding the Item you are dragging over, you can use the DragOver event, and the OriginalSource property in combination with the ParentOfType extensions to get the target item.

Hope this makes sense! 

Regards,
Nik
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
DragAndDrop
Asked by
Stefania
Top achievements
Rank 2
Answers by
Nick
Telerik team
Share this question
or