This question is locked. New answers and comments are not allowed.
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
MainPage.xaml.cs
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?
Here is a sample app demonstrating the problem:
MainPage.xaml
<UserControl x:Class="TelerikDNDTest.MainPage" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 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?