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

Drag and drop fails of destination does not have a Background color set

1 Answer 40 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Matt Greer
Top achievements
Rank 1
Matt Greer asked on 30 Nov 2010, 10:57 PM
Ugh. I just spent several hours trying to figure out why my DnD was not working. It turns out if a destination control does not have its Background property set, the DnD will fail and result in DropImpossible.

Here is a sample app demonstrating the problem:

MainPage.xaml
<UserControl x:Class="TelerikDNDTest.MainPage"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <StackPanel Margin="80">
            <ListBox x:Name="_myListBox" Width="200" Height="100" BorderBrush="Black" BorderThickness="1">
                <ListBox.Items>
                    <ListBoxItem>hello</ListBoxItem>
                </ListBox.Items>
            </ListBox>
            <TextBlock x:Name="_myTextBlock" Text="No dnd yet" HorizontalAlignment="Center" />
        </StackPanel>
    </Grid>
</UserControl>



MainPage.xaml.cs
using System.Windows.Controls;
using Telerik.Windows.Controls.DragDrop;
 
namespace TelerikDNDTest
{
    public partial class MainPage : UserControl
    {
        private void OnDragQuery(object sender, DragDropQueryEventArgs e)
        {
            if (e.Source == _myListBox)
            {
                e.QueryResult = true;
 
                ContentControl cue = new ContentControl();
                TextBlock tb = new TextBlock();
                tb.Text = "Dragging!";
                cue.Content = tb;
 
                e.Options.Payload = "dragging";
                e.Options.DragCue = cue;
 
                e.Handled = true;
            }
        }
 
        private void OnDropQuery(object sender, DragDropQueryEventArgs e)
        {
            if (e.Options.Status == DragStatus.DropDestinationQuery && e.Options.Source == _myListBox)
            {
                e.QueryResult = !ReferenceEquals(e.Options.Source, e.Options.Destination);
                e.Handled = (bool)e.QueryResult;
            }
        }
 
        private int _successCount = 0;
 
        private void DropSuccess()
        {
            _myTextBlock.Text = "DND Success " + (++_successCount);
        }
 
        private void OnDropInfo(object sender, DragDropEventArgs e)
        {
            if (e.Options.Status == DragStatus.DropComplete)
            {
                if (e.Options.Source == _myListBox)
                {
                    DropSuccess();
                    e.Handled = true;
                }
            }
        }
 
        private void SetupDragAndDrop()
        {
            RadDragAndDropManager.AddDragQueryHandler(this, OnDragQuery);
            RadDragAndDropManager.AddDropQueryHandler(this, OnDropQuery);
            RadDragAndDropManager.AddDropInfoHandler(this, OnDropInfo);
 
            RadDragAndDropManager.SetAllowDrag(_myListBox, true);
            RadDragAndDropManager.SetAllowDrop(LayoutRoot, true);
        }
 
        public MainPage()
        {
            InitializeComponent();
            SetupDragAndDrop();
        }
    }
}



In this sample app as is, the drag and drop from the listbox out into the parent grid will never succeed. However, if you give the parent Grid (LayoutRoot in this example) a Background color (even Transparent works fine), then the drag and drop will succeed.

Is there something I am doing wrong to cause this?

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 01 Dec 2010, 08:26 AM
Hi Matt Greer,

The behavior you are getting is the expected one in the Silverlight platform. The reason is that no events are raised in case no background is set. As you successfully figured it out, even setting the Background to Transparent does the job.
 

Kind regards,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
DragAndDrop
Asked by
Matt Greer
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or