Drag TextBlock from One User Control and Drop to other user control

3 posts, 0 answers
  1. HARSH
    HARSH avatar
    19 posts
    Member since:
    Oct 2008

    Posted 07 Jul 2010 Link to this post

    Hi,

    I want to drag 3 TextBlock from one user control and want to create textblock with same content in other user control.
    So i am adding drag event is different textblocks of first user control and drop events in a grid of second user control.
    First time when i am dropping an item it is working fine.
    From next item onwards it is showing me arrow line which it has drawn while dropping first item.

    My code is:
    //UserControl2

     

     

    private void OnDropInfo(object sender, DragDropEventArgs e)

     

    {

     

     

    if ( e.Options.Status==DragStatus.DropComplete)

     

    {

     

     

     

     

    //Code for custom processing
    }
    }


     

     

    void OnDropQuery(object sender, DragDropQueryEventArgs e)

     

    {

    e.QueryResult =

     

    true;

     

    }

     //UserControl1

     

     

    void OnDragInfo(object sender, DragDropEventArgs e)

     

    {

    }

     

     

     

    protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e)

     

    {

     

     

    TextBlock labelItem = e.Options.Source as TextBlock;

     

    e.Options.Payload = labelItem;

     

     

    ContentControl cue = new ContentControl();

     

     

     

    StackPanel spanel = new StackPanel();

     

    spanel.Children.Add(

     

    new TextBlock(){Text =labelItem.Text});

     

    cue.Content =spanel;

     

     

    e.Options.DragCue = cue;

    e.Options.ArrowCue =

     

    RadDragAndDropManager.GenerateArrowCue();

     

    e.QueryResult =

     

    true;

     

     

    }


    Please provide me some sample code to fix this.
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 12 Jul 2010 Link to this post

    Hello HARSH,

    i noticed that you are generating an ArrowCue each time the OnDragQuery() fires, can you try generating it only when the status of the drag/drop operation is DragQuery instead, like so:
    protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e)
    {
        if (e.Options.Status == DragStatus.DragQuery)
        {
            TextBlock labelItem = e.Options.Source as TextBlock;
            e.Options.Payload = labelItem;
            ContentControl cue = new ContentControl();
            StackPanel spanel = new StackPanel();
            spanel.Children.Add(new TextBlock() { Text = labelItem.Text });
            cue.Content = spanel;
            e.Options.DragCue = cue;
            e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue();
        }
        e.QueryResult = true;
    }

    Please give this approach a try and let me know if it works for you.

    Best wishes,
    Tina Stancheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. HARSH
    HARSH avatar
    19 posts
    Member since:
    Oct 2008

    Posted 20 Jul 2010 Link to this post

    Thanks Tina.
    It Works.
Back to Top