Treeview D&D Tooltip

2 posts, 0 answers
  1. Stefania
    Stefania avatar
    107 posts
    Member since:
    May 2013

    Posted 27 Sep 2013 Link to this post

    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
  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 27 Sep 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top