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

DragComplete status not getting set on Drop

6 Answers 107 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Carolyn
Top achievements
Rank 1
Carolyn asked on 06 Jul 2009, 05:38 PM
After upgrading to the Q2 release of the Silverlight Controls, I have noticed that my DragDrop controls are no longer functioning properly. I am using the supplied code from the Examples page:

void OnDragInfo(object sender, DragDropEventArgs e)  
{  
    DraggableListBox box = sender as DraggableListBox;  
    IList<ApplicationInfo> itemsSource = box.ItemsSource as IList<ApplicationInfo>;  
    ApplicationInfo payload = e.Options.Payload as ApplicationInfo;  
 
    if (e.Options.Status == DragStatus.DragComplete)  
    {  
        if (payload != null && itemsSource.Contains(payload))  
        {  
            itemsSource.Remove(payload);  
        }  
    }  
}  
 

When execution reaches line 7, after releasing the left mouse button in the ListBox control that I wish to Drop an item, instead of getting a "DragComplete" status, I am getting a DragCancel status, and therefore code execution stops at this line.

Please note that this same code block worked when using the Q1 version of the controls.

6 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 07 Jul 2009, 06:56 AM
Hi Joe,

I am sorry for breaking existing code. I checked several examples and example applications where the DragDrop fires the DropCompleted event as expected.

Also, I am attaching the ListBox DragDrop example here. In this project the event is fired, so there is something that I am missing.

- Are you using SL2 or SL3?
- Is the ListBox in a Popup or in another control?
- Is there a Canvas somewhere in the Visual tree below the ListBox?
- Any other information that can help us reproduce the context?

Regards,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Carolyn
Top achievements
Rank 1
answered on 07 Jul 2009, 12:14 PM
Miroslav:

To answer yuor questions:

- Are you using SL2 or SL3?
    * Silverlight 3

- Is the ListBox in a Popup or in another control?
    * The Listboxes reside inside of a RadWindow Control ("AssignedItemsWindow"):

<Grid x:Name="LayoutRoot">  
        <telerikNavigation:RadWindow x:Name="winItems" WindowStartupLocation="CenterScreen" Padding="10 10 10 10" ResizeMode="NoResize"   
            BorderBackground="#FF0000FF" BorderBrush="#FF0000FF" IconTemplate="{x:Null}" > 
            <telerikNavigation:RadWindow.Header> 
                <TextBlock x:Name="tbHeader" Padding="0 0 5 0" Foreground="White" /> 
            </telerikNavigation:RadWindow.Header> 
            <telerikNavigation:RadWindow.Icon> 
                <Image x:Name="imgIcon" /> 
            </telerikNavigation:RadWindow.Icon> 
            <StackPanel Orientation="Horizontal" Margin="0,10,0,0">  
                <Grid HorizontalAlignment="Stretch">  
                    <Grid.ColumnDefinitions> 
                        <ColumnDefinition Width="200" /> 
                        <ColumnDefinition Width="200" /> 
                        <ColumnDefinition Width="200" /> 
                    </Grid.ColumnDefinitions> 
 
                    <!--Unassigned Items--> 
                    <Grid> 
                        <Border Height="30" VerticalAlignment="Top" CornerRadius="5,5,0,0" Margin="5 5 5 5" BorderBrush="#FF0413CA" BorderThickness="1,1,1,0">  
                            <Border.Background> 
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">  
                                    <GradientStop Color="#FF0413CA"/>  
                                    <GradientStop Color="#FF63ABF5" Offset="1"/>  
                                </LinearGradientBrush> 
                            </Border.Background> 
                            <TextBlock x:Name="tbUnassignedHeader" Margin="10,5" Foreground="#FFFFFFFF" FontSize="12" HorizontalAlignment="Left" /> 
                        </Border> 
                        <local:DraggableListBox x:Name="dlbUnassignedItems"  Margin="5,30,5,5" BorderBrush="#FF0413CA" BorderThickness="1,0,1,1" 
                            Height="300" ScrollViewer.HorizontalScrollBarVisibility="Auto" VerticalAlignment="Top" > 
                            <local:DraggableListBox.Resources> 
                                <DataTemplate x:Key="ApplicationDragTemplate">  
                                    <Image Source="{Binding IconPath}" /> 
                                </DataTemplate> 
                            </local:DraggableListBox.Resources> 
                            <local:DraggableListBox.ItemTemplate> 
                                <DataTemplate> 
                                    <StackPanel HorizontalAlignment="Stretch" Orientation="Horizontal">  
                                        <Image Source="{Binding IconPath}" Margin="0 0 3 0" HorizontalAlignment="Center" VerticalAlignment="Center" Height="16" /> 
                                        <TextBlock Text="{Binding Name}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
                                    </StackPanel> 
                                </DataTemplate> 
                            </local:DraggableListBox.ItemTemplate> 
                            <local:DraggableListBox.ItemsPanel> 
                                <ItemsPanelTemplate> 
                                    <primitives:RadUniformGrid Columns="1" HorizontalAlignment="Left" VerticalAlignment="Top"/>  
                                </ItemsPanelTemplate> 
                            </local:DraggableListBox.ItemsPanel> 
                        </local:DraggableListBox> 
                    </Grid> 
 
                    <!--Explanation--> 
                    <StackPanel Orientation="Vertical" Grid.Column="1" > 
                        <Border BorderBrush="Gray" Background="#FFCAE4ED" BorderThickness="1" VerticalAlignment="Top" HorizontalAlignment="Center"   
                            Margin="5 5 5 5">  
                            <TextBlock x:Name="tbExplanation" HorizontalAlignment="Center" TextWrapping="Wrap"  Margin="10" FontSize="10" /> 
                        </Border> 
                        <telerikNavigation:RadMenuItem x:Name="miAssignAll" Header="Assign All" Margin="0 20 0 0" > 
                            <telerikNavigation:RadMenuItem.Icon> 
                                <Image Source="../../Images/Components.png" Margin="3 0 0 0"/>  
                            </telerikNavigation:RadMenuItem.Icon> 
                        </telerikNavigation:RadMenuItem> 
                        <telerikNavigation:RadMenuItem x:Name="miUnassignAll" Header="Unassign All" Margin="0 20 0 0" > 
                            <telerikNavigation:RadMenuItem.Icon> 
                                <Image Source="../../Images/Components.png" Margin="3 0 0 0" /> 
                            </telerikNavigation:RadMenuItem.Icon> 
                        </telerikNavigation:RadMenuItem> 
                    </StackPanel> 
 
                    <!--Assigned Items--> 
                    <Grid Grid.Column="2">  
                        <Border Height="30" VerticalAlignment="Top" CornerRadius="5,5,0,0" Margin="5 5 5 5" BorderBrush="#FF0413CA" BorderThickness="1,1,1,0">  
                            <Border.Background> 
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">  
                                    <GradientStop Color="#FF0413CA"/>  
                                    <GradientStop Color="#FF63ABF5" Offset="1"/>  
                                </LinearGradientBrush> 
                            </Border.Background> 
                            <TextBlock x:Name="tbAssignedHeader"  Margin="10,5" Foreground="#FFFFFFFF" FontSize="12" HorizontalAlignment="Left" /> 
                        </Border> 
                        <local:DraggableListBox x:Name="dlbAssignedItems"  Margin="5,30,5,5" BorderBrush="#FF0413CA" BorderThickness="1,0,1,1" 
                            Height="300" ScrollViewer.HorizontalScrollBarVisibility="Auto" VerticalAlignment="Top" > 
                            <local:DraggableListBox.Resources> 
                                <DataTemplate x:Key="ApplicationDragTemplate">  
                                    <Image Source="{Binding IconPath}" /> 
                                </DataTemplate> 
                            </local:DraggableListBox.Resources> 
                            <local:DraggableListBox.ItemTemplate> 
                                <DataTemplate> 
                                    <StackPanel HorizontalAlignment="Stretch" Orientation="Horizontal">  
                                        <Image Source="{Binding IconPath}" Margin="0 0 3 0" HorizontalAlignment="Center" VerticalAlignment="Center" Height="16" /> 
                                        <TextBlock Text="{Binding Name}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
                                    </StackPanel> 
                                </DataTemplate> 
                            </local:DraggableListBox.ItemTemplate> 
                            <local:DraggableListBox.ItemsPanel> 
                                <ItemsPanelTemplate> 
                                    <primitives:RadUniformGrid Columns="1" HorizontalAlignment="Left" VerticalAlignment="Top" /> 
                                </ItemsPanelTemplate> 
                            </local:DraggableListBox.ItemsPanel> 
                        </local:DraggableListBox> 
                    </Grid> 
                </Grid> 
            </StackPanel> 
        </telerikNavigation:RadWindow> 
    </Grid> 

Here's the Draggable Listbox Class
using System;  
using System.Collections.Generic;  
using System.Collections.ObjectModel;  
using System.ComponentModel;  
using System.Windows;  
using System.Windows.Controls;  
using System.Windows.Media;  
 
using Telerik.Windows;  
using Telerik.Windows.Controls.DragDrop;  
 
namespace Xerox.Genesis.Platform.Admin  
{  
    public class DraggableListBox : ListBox  
    {
        #region Private Instance Variables  
 
        Brush listBoxDefaultBrush;  
        Brush listBoxDragPossible = new SolidColorBrush(Colors.Orange);
        #endregion  
 
        #region Public Event Definitions  
 
        public event EventHandler<DragDropQueryEventArgs> DragQuery  
        {  
            add { this.AddHandler(RadDragAndDropManager.DragQueryEvent, value); }  
            remove { this.RemoveHandler(RadDragAndDropManager.DragQueryEvent, value); }  
        }  
 
        public event EventHandler<DragDropQueryEventArgs> DropQuery  
        {  
            add { this.AddHandler(RadDragAndDropManager.DropQueryEvent, value); }  
            remove { this.RemoveHandler(RadDragAndDropManager.DropQueryEvent, value); }  
        }  
 
        public event EventHandler<DragDropEventArgs> DragInfo  
        {  
            add { this.AddHandler(RadDragAndDropManager.DragInfoEvent, value); }  
            remove { this.RemoveHandler(RadDragAndDropManager.DragInfoEvent, value); }  
        }  
 
        public event EventHandler<DragDropEventArgs> DropInfo  
        {  
            add { this.AddHandler(RadDragAndDropManager.DropInfoEvent, value); }  
            remove { this.RemoveHandler(RadDragAndDropManager.DropInfoEvent, value); }  
        }
        #endregion  
 
        #region Constructors  
 
        public DraggableListBox()  
        {  
            RadDragAndDropManager.SetAllowDrop(thistrue);  
 
            this.DragQuery += new EventHandler<DragDropQueryEventArgs>(OnDragQuery);  
            this.DragInfo += new EventHandler<DragDropEventArgs>(OnDragInfo);  
            this.DropQuery += new EventHandler<DragDropQueryEventArgs>(OnDropQuery);  
            this.DropInfo += new EventHandler<DragDropEventArgs>(OnDropInfo);  
        }
        #endregion  
 
        #region Public Overridden Methods  
 
        public override void OnApplyTemplate()  
        {  
            base.OnApplyTemplate();  
            listBoxDefaultBrush = BorderBrush;  
        }
        #endregion  
 
        #region Protected Overridden Methods  
 
        protected override void PrepareContainerForItemOverride(DependencyObject element, object item)  
        {  
            base.PrepareContainerForItemOverride(element, item);  
            RadDragAndDropManager.SetAllowDrag(element, true);  
            RadDragAndDropManager.SetAllowDrop(element, true);  
        }  
 
        protected override void ClearContainerForItemOverride(DependencyObject element, object item)  
        {  
            base.ClearContainerForItemOverride(element, item);  
            RadDragAndDropManager.SetAllowDrag(element, false);  
            RadDragAndDropManager.SetAllowDrop(element, false);  
        }
        #endregion  
 
        #region Protected Event Handlers  
 
        protected void OnDropInfo(object sender, DragDropEventArgs e)  
        {  
            DraggableListBox box = sender as DraggableListBox;  
            IList<ListBoxDataSource> itemsSource = box.ItemsSource as IList<ListBoxDataSource>;  
            ListBoxDataSource payload = e.Options.Payload as ListBoxDataSource;  
 
            if (e.Options.Status == DragStatus.DropPossible)  
                box.BorderBrush = listBoxDragPossible;  
            else 
                box.BorderBrush = listBoxDefaultBrush;  
 
            if (e.Options.Status == DragStatus.DropComplete && (!itemsSource.Contains(payload)))  
                itemsSource.Add(payload);  
        }  
 
        protected void OnDropQuery(object sender, DragDropQueryEventArgs e)  
        {  
            DraggableListBox box = sender as DraggableListBox;  
            IList<ListBoxDataSource> itemsSource = box.ItemsSource as IList<ListBoxDataSource>;  
            ListBoxDataSource payload = e.Options.Payload as ListBoxDataSource;  
 
            e.QueryResult = payload != null && !itemsSource.Contains(payload);  
        }  
 
        protected void OnDragInfo(object sender, DragDropEventArgs e)  
        {  
            DraggableListBox box = sender as DraggableListBox;  
            IList<ListBoxDataSource> itemsSource = box.ItemsSource as IList<ListBoxDataSource>;  
            ListBoxDataSource payload = e.Options.Payload as ListBoxDataSource;  
 
            if (e.Options.Status == DragStatus.DragComplete && (payload != null && itemsSource.Contains(payload)))  
                itemsSource.Remove(payload);  
        }  
 
        protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e)  
        {  
            DraggableListBox box = sender as DraggableListBox;  
 
            e.QueryResult = true;  
 
            if (e.Options.Status == DragStatus.DragQuery)  
            {  
                e.Options.SourceCueHost = null;  
                e.Options.Payload = box.SelectedItem;  
                ContentControl cue = new ContentControl();  
                cue.ContentTemplate = this.Resources["ApplicationDragTemplate"as DataTemplate;  
                cue.Content = box.SelectedItem;  
                e.Options.DragCue = cue;  
                e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue();  
            }  
        }
        #endregion  
    }  
 
    public class ListBoxDataSource : INotifyPropertyChanged  
    {
        #region Private Instance Variables  
 
        private Guid _Id;  
        private String _IconPath;  
        private String _Name;
        #endregion  
 
        #region Public Property Accessors  
 
        public Guid Id  
        {  
            get 
            {  
                return this._Id;  
            }  
            set 
            {  
                if (this._Id != value)  
                {  
                    this._Id = value;  
                    OnPropertyChanged("Id");  
                }  
            }  
        }  
                  
        public String IconPath  
        {  
            get 
            {  
                return this._IconPath;  
            }  
            set 
            {  
                if (this._IconPath != value)  
                {  
                    this._IconPath = value;  
                    OnPropertyChanged("IconPath");  
                }  
            }  
        }  
                  
        public String Name  
        {  
            get 
            {  
                return this._Name;  
            }  
            set 
            {  
                if (this._Name != value)  
                {  
                    this._Name = value;  
                    OnPropertyChanged("Name");  
                }  
            }  
        }
        #endregion  
 
        #region Constructors  
 
        public ListBoxDataSource(Guid id, String name)  
        {  
            this._Id = id;  
            this._Name = name;  
            this._IconPath = "../../Images/NoIcon.png";  
        }  
 
        public ListBoxDataSource(Guid id, String name, String iconPath) : this(id, name)  
        {  
            this._IconPath = iconPath;  
        }
        #endregion  
 
        #region Public Events  
 
        /// <summary>  
        /// Raised when the value of one of the properties changes.  
        /// </summary>  
        public event PropertyChangedEventHandler PropertyChanged;
        #endregion  
 
        #region Protected Event Handlers  
 
        /// <summary>  
        /// Called when the value of a property changes.  
        /// </summary>  
        /// <param name="propertyName">The name of the property that has changed.</param>  
        protected virtual void OnPropertyChanged(String propertyName)  
        {  
            if (String.IsNullOrEmpty(propertyName))  
                return;  
              
            if (PropertyChanged != null)  
                PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));  
        }
        #endregion  
    }  
}  
 

Here's the code that renders the AssignedItemsWindow control:
private void RenderAssignedItemsWindow()  
{  
    // Create a new instance of AssignedItemsWindow  
    AssignedItemsWindow AIW = new AssignedItemsWindow()  
    // Wire up Drop Events  
    AIW.dlbAssignedItems.DropInfo += new EventHandler<Telerik.Windows.Controls.DragDrop.DragDropEventArgs>(dlbAssignedItems_DropInfo);  
    AIW.dlbUnassignedItems.DropInfo += new EventHandler<Telerik.Windows.Controls.DragDrop.DragDropEventArgs>(dlbUnassignedItems_DropInfo);  
    AIW.miAssignAll.Click += new RoutedEventHandler(miAssignAll_Click);  
    AIW.miUnassignAll.Click += new RoutedEventHandler(miUnassignAll_Click);  
 
    // Bind the appropriate ObservableCollections to the AssignedItemsWindow's Draggable List Boxes  
    AIW.dlbAssignedItems.ItemsSource = *** Some List *** 
    AIW.dlbUnassignedItems.ItemsSource = *** Some List ***
 
    // Add the AssignedItemsWindow to this control  
    LayoutRoot.Children.Add(AIW);  
 
    // Render the AssignedItemsWindow in Dialog (Modal) mode  
    AIW.winItems.ShowDialog();  

Here's the code to perform some action on the DropInfo event:
protected void dlbAssignedItems_DropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e)  
{  
    ///Perform some action  
}  
 
protected void dlbUnassignedItems_DropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e)  
{  
    ///Perform some action  

Hopefully this helps.
0
Miroslav
Telerik team
answered on 07 Jul 2009, 01:40 PM
Thanks for the clarifications!

Unfortunately we have not released a SL3-specific build yet and there may be some issues with the SL2 build of the controls. We plan to release a SL 3 build with the SP release, which will be out in a couple of weeks.

In the meantime I will look for a workaround for this specific case and follow up here.

Thanks for bringing our attention to this problem!

Regards,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Miroslav
Telerik team
answered on 15 Jul 2009, 11:46 AM
Hi Joe,

I just wanted to follow on this issue. We released a SL3 build last Friday. Not everything is up to standards yet but the DragDrop issue should have been resolved.

You can find the assemblies under latest internal builds.

Regards,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Yuri Brutyan
Top achievements
Rank 1
answered on 24 Feb 2010, 03:19 PM
Hi All,

I'm getting the same error when used RadDragAndDropManager in the popup region. I use Prism2 framework.
If I use Radwindow instead of region, it works fine.

Is there a way to resolve this problem?

Best regards,
Yuri
0
Miroslav
Telerik team
answered on 26 Feb 2010, 02:18 PM
Hi Yuri Brutyan,

Yes, this is because the DragDrop works by searching the VisualTree for potential drop targets and we do know about the opened popups.

Opened popups need to be added in the ParticipatingVisualRoots collection for a successful drop, more information is available here:

http://www.telerik.com/community/forums/silverlight/drag-and-drop/drag-amp-drop-on-child-window.aspx

http://www.telerik.com/community/forums/silverlight/treeview/can-t-use-drag-and-drop-on-treeview-on-childwindow.aspx

Kind regards,
Miroslav
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.
Tags
DragAndDrop
Asked by
Carolyn
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Carolyn
Top achievements
Rank 1
Yuri Brutyan
Top achievements
Rank 1
Share this question
or