DragComplete status not getting set on Drop

7 posts, 0 answers
  1. Carolyn
    Carolyn avatar
    14 posts
    Member since:
    May 2006

    Posted 06 Jul 2009 Link to this post

    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:

    1 void OnDragInfo(object sender, DragDropEventArgs e)  
    2 {  
    3     DraggableListBox box = sender as DraggableListBox;  
    4     IList<ApplicationInfo> itemsSource = box.ItemsSource as IList<ApplicationInfo>;  
    5     ApplicationInfo payload = e.Options.Payload as ApplicationInfo;  
    6  
    7     if (e.Options.Status == DragStatus.DragComplete)  
    8     {  
    9         if (payload != null && itemsSource.Contains(payload))  
    10         {  
    11             itemsSource.Remove(payload);  
    12         }  
    13     }  
    14 }  
    15  

    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.
  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 07 Jul 2009 Link to this post

    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.
  3. DevCraft banner
  4. Carolyn
    Carolyn avatar
    14 posts
    Member since:
    May 2006

    Posted 07 Jul 2009 Link to this post

    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"):

    1 <Grid x:Name="LayoutRoot">  
    2         <telerikNavigation:RadWindow x:Name="winItems" WindowStartupLocation="CenterScreen" Padding="10 10 10 10" ResizeMode="NoResize"   
    3             BorderBackground="#FF0000FF" BorderBrush="#FF0000FF" IconTemplate="{x:Null}" > 
    4             <telerikNavigation:RadWindow.Header> 
    5                 <TextBlock x:Name="tbHeader" Padding="0 0 5 0" Foreground="White" /> 
    6             </telerikNavigation:RadWindow.Header> 
    7             <telerikNavigation:RadWindow.Icon> 
    8                 <Image x:Name="imgIcon" /> 
    9             </telerikNavigation:RadWindow.Icon> 
    10             <StackPanel Orientation="Horizontal" Margin="0,10,0,0">  
    11                 <Grid HorizontalAlignment="Stretch">  
    12                     <Grid.ColumnDefinitions> 
    13                         <ColumnDefinition Width="200" /> 
    14                         <ColumnDefinition Width="200" /> 
    15                         <ColumnDefinition Width="200" /> 
    16                     </Grid.ColumnDefinitions> 
    17  
    18                     <!--Unassigned Items--> 
    19                     <Grid> 
    20                         <Border Height="30" VerticalAlignment="Top" CornerRadius="5,5,0,0" Margin="5 5 5 5" BorderBrush="#FF0413CA" BorderThickness="1,1,1,0">  
    21                             <Border.Background> 
    22                                 <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">  
    23                                     <GradientStop Color="#FF0413CA"/>  
    24                                     <GradientStop Color="#FF63ABF5" Offset="1"/>  
    25                                 </LinearGradientBrush> 
    26                             </Border.Background> 
    27                             <TextBlock x:Name="tbUnassignedHeader" Margin="10,5" Foreground="#FFFFFFFF" FontSize="12" HorizontalAlignment="Left" /> 
    28                         </Border> 
    29                         <local:DraggableListBox x:Name="dlbUnassignedItems"  Margin="5,30,5,5" BorderBrush="#FF0413CA" BorderThickness="1,0,1,1" 
    30                             Height="300" ScrollViewer.HorizontalScrollBarVisibility="Auto" VerticalAlignment="Top" > 
    31                             <local:DraggableListBox.Resources> 
    32                                 <DataTemplate x:Key="ApplicationDragTemplate">  
    33                                     <Image Source="{Binding IconPath}" /> 
    34                                 </DataTemplate> 
    35                             </local:DraggableListBox.Resources> 
    36                             <local:DraggableListBox.ItemTemplate> 
    37                                 <DataTemplate> 
    38                                     <StackPanel HorizontalAlignment="Stretch" Orientation="Horizontal">  
    39                                         <Image Source="{Binding IconPath}" Margin="0 0 3 0" HorizontalAlignment="Center" VerticalAlignment="Center" Height="16" /> 
    40                                         <TextBlock Text="{Binding Name}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
    41                                     </StackPanel> 
    42                                 </DataTemplate> 
    43                             </local:DraggableListBox.ItemTemplate> 
    44                             <local:DraggableListBox.ItemsPanel> 
    45                                 <ItemsPanelTemplate> 
    46                                     <primitives:RadUniformGrid Columns="1" HorizontalAlignment="Left" VerticalAlignment="Top"/>  
    47                                 </ItemsPanelTemplate> 
    48                             </local:DraggableListBox.ItemsPanel> 
    49                         </local:DraggableListBox> 
    50                     </Grid> 
    51  
    52                     <!--Explanation--> 
    53                     <StackPanel Orientation="Vertical" Grid.Column="1" > 
    54                         <Border BorderBrush="Gray" Background="#FFCAE4ED" BorderThickness="1" VerticalAlignment="Top" HorizontalAlignment="Center"   
    55                             Margin="5 5 5 5">  
    56                             <TextBlock x:Name="tbExplanation" HorizontalAlignment="Center" TextWrapping="Wrap"  Margin="10" FontSize="10" /> 
    57                         </Border> 
    58                         <telerikNavigation:RadMenuItem x:Name="miAssignAll" Header="Assign All" Margin="0 20 0 0" > 
    59                             <telerikNavigation:RadMenuItem.Icon> 
    60                                 <Image Source="../../Images/Components.png" Margin="3 0 0 0"/>  
    61                             </telerikNavigation:RadMenuItem.Icon> 
    62                         </telerikNavigation:RadMenuItem> 
    63                         <telerikNavigation:RadMenuItem x:Name="miUnassignAll" Header="Unassign All" Margin="0 20 0 0" > 
    64                             <telerikNavigation:RadMenuItem.Icon> 
    65                                 <Image Source="../../Images/Components.png" Margin="3 0 0 0" /> 
    66                             </telerikNavigation:RadMenuItem.Icon> 
    67                         </telerikNavigation:RadMenuItem> 
    68                     </StackPanel> 
    69  
    70                     <!--Assigned Items--> 
    71                     <Grid Grid.Column="2">  
    72                         <Border Height="30" VerticalAlignment="Top" CornerRadius="5,5,0,0" Margin="5 5 5 5" BorderBrush="#FF0413CA" BorderThickness="1,1,1,0">  
    73                             <Border.Background> 
    74                                 <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">  
    75                                     <GradientStop Color="#FF0413CA"/>  
    76                                     <GradientStop Color="#FF63ABF5" Offset="1"/>  
    77                                 </LinearGradientBrush> 
    78                             </Border.Background> 
    79                             <TextBlock x:Name="tbAssignedHeader"  Margin="10,5" Foreground="#FFFFFFFF" FontSize="12" HorizontalAlignment="Left" /> 
    80                         </Border> 
    81                         <local:DraggableListBox x:Name="dlbAssignedItems"  Margin="5,30,5,5" BorderBrush="#FF0413CA" BorderThickness="1,0,1,1" 
    82                             Height="300" ScrollViewer.HorizontalScrollBarVisibility="Auto" VerticalAlignment="Top" > 
    83                             <local:DraggableListBox.Resources> 
    84                                 <DataTemplate x:Key="ApplicationDragTemplate">  
    85                                     <Image Source="{Binding IconPath}" /> 
    86                                 </DataTemplate> 
    87                             </local:DraggableListBox.Resources> 
    88                             <local:DraggableListBox.ItemTemplate> 
    89                                 <DataTemplate> 
    90                                     <StackPanel HorizontalAlignment="Stretch" Orientation="Horizontal">  
    91                                         <Image Source="{Binding IconPath}" Margin="0 0 3 0" HorizontalAlignment="Center" VerticalAlignment="Center" Height="16" /> 
    92                                         <TextBlock Text="{Binding Name}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
    93                                     </StackPanel> 
    94                                 </DataTemplate> 
    95                             </local:DraggableListBox.ItemTemplate> 
    96                             <local:DraggableListBox.ItemsPanel> 
    97                                 <ItemsPanelTemplate> 
    98                                     <primitives:RadUniformGrid Columns="1" HorizontalAlignment="Left" VerticalAlignment="Top" /> 
    99                                 </ItemsPanelTemplate> 
    100                             </local:DraggableListBox.ItemsPanel> 
    101                         </local:DraggableListBox> 
    102                     </Grid> 
    103                 </Grid> 
    104             </StackPanel> 
    105         </telerikNavigation:RadWindow> 
    106     </Grid> 

    Here's the Draggable Listbox Class
    1 using System;  
    2 using System.Collections.Generic;  
    3 using System.Collections.ObjectModel;  
    4 using System.ComponentModel;  
    5 using System.Windows;  
    6 using System.Windows.Controls;  
    7 using System.Windows.Media;  
    8  
    9 using Telerik.Windows;  
    10 using Telerik.Windows.Controls.DragDrop;  
    11  
    12 namespace Xerox.Genesis.Platform.Admin  
    13 {  
    14     public class DraggableListBox : ListBox  
    15     {
    16         #region Private Instance Variables  
    17  
    18         Brush listBoxDefaultBrush;  
    19         Brush listBoxDragPossible = new SolidColorBrush(Colors.Orange);
    20
    21         #endregion  
    22  
    23         #region Public Event Definitions  
    24  
    25         public event EventHandler<DragDropQueryEventArgs> DragQuery  
    26         {  
    27             add { this.AddHandler(RadDragAndDropManager.DragQueryEvent, value); }  
    28             remove { this.RemoveHandler(RadDragAndDropManager.DragQueryEvent, value); }  
    29         }  
    30  
    31         public event EventHandler<DragDropQueryEventArgs> DropQuery  
    32         {  
    33             add { this.AddHandler(RadDragAndDropManager.DropQueryEvent, value); }  
    34             remove { this.RemoveHandler(RadDragAndDropManager.DropQueryEvent, value); }  
    35         }  
    36  
    37         public event EventHandler<DragDropEventArgs> DragInfo  
    38         {  
    39             add { this.AddHandler(RadDragAndDropManager.DragInfoEvent, value); }  
    40             remove { this.RemoveHandler(RadDragAndDropManager.DragInfoEvent, value); }  
    41         }  
    42  
    43         public event EventHandler<DragDropEventArgs> DropInfo  
    44         {  
    45             add { this.AddHandler(RadDragAndDropManager.DropInfoEvent, value); }  
    46             remove { this.RemoveHandler(RadDragAndDropManager.DropInfoEvent, value); }  
    47         }
    48
    49         #endregion  
    50  
    51         #region Constructors  
    52  
    53         public DraggableListBox()  
    54         {  
    55             RadDragAndDropManager.SetAllowDrop(thistrue);  
    56  
    57             this.DragQuery += new EventHandler<DragDropQueryEventArgs>(OnDragQuery);  
    58             this.DragInfo += new EventHandler<DragDropEventArgs>(OnDragInfo);  
    59             this.DropQuery += new EventHandler<DragDropQueryEventArgs>(OnDropQuery);  
    60             this.DropInfo += new EventHandler<DragDropEventArgs>(OnDropInfo);  
    61         }
    62
    63         #endregion  
    64  
    65         #region Public Overridden Methods  
    66  
    67         public override void OnApplyTemplate()  
    68         {  
    69             base.OnApplyTemplate();  
    70             listBoxDefaultBrush = BorderBrush;  
    71         }
    72
    73         #endregion  
    74  
    75         #region Protected Overridden Methods  
    76  
    77         protected override void PrepareContainerForItemOverride(DependencyObject element, object item)  
    78         {  
    79             base.PrepareContainerForItemOverride(element, item);  
    80             RadDragAndDropManager.SetAllowDrag(element, true);  
    81             RadDragAndDropManager.SetAllowDrop(element, true);  
    82         }  
    83  
    84         protected override void ClearContainerForItemOverride(DependencyObject element, object item)  
    85         {  
    86             base.ClearContainerForItemOverride(element, item);  
    87             RadDragAndDropManager.SetAllowDrag(element, false);  
    88             RadDragAndDropManager.SetAllowDrop(element, false);  
    89         }
    90
    91         #endregion  
    92  
    93         #region Protected Event Handlers  
    94  
    95         protected void OnDropInfo(object sender, DragDropEventArgs e)  
    96         {  
    97             DraggableListBox box = sender as DraggableListBox;  
    98             IList<ListBoxDataSource> itemsSource = box.ItemsSource as IList<ListBoxDataSource>;  
    99             ListBoxDataSource payload = e.Options.Payload as ListBoxDataSource;  
    100  
    101             if (e.Options.Status == DragStatus.DropPossible)  
    102                 box.BorderBrush = listBoxDragPossible;  
    103             else 
    104                 box.BorderBrush = listBoxDefaultBrush;  
    105  
    106             if (e.Options.Status == DragStatus.DropComplete && (!itemsSource.Contains(payload)))  
    107                 itemsSource.Add(payload);  
    108         }  
    109  
    110         protected void OnDropQuery(object sender, DragDropQueryEventArgs e)  
    111         {  
    112             DraggableListBox box = sender as DraggableListBox;  
    113             IList<ListBoxDataSource> itemsSource = box.ItemsSource as IList<ListBoxDataSource>;  
    114             ListBoxDataSource payload = e.Options.Payload as ListBoxDataSource;  
    115  
    116             e.QueryResult = payload != null && !itemsSource.Contains(payload);  
    117         }  
    118  
    119         protected void OnDragInfo(object sender, DragDropEventArgs e)  
    120         {  
    121             DraggableListBox box = sender as DraggableListBox;  
    122             IList<ListBoxDataSource> itemsSource = box.ItemsSource as IList<ListBoxDataSource>;  
    123             ListBoxDataSource payload = e.Options.Payload as ListBoxDataSource;  
    124  
    125             if (e.Options.Status == DragStatus.DragComplete && (payload != null && itemsSource.Contains(payload)))  
    126                 itemsSource.Remove(payload);  
    127         }  
    128  
    129         protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e)  
    130         {  
    131             DraggableListBox box = sender as DraggableListBox;  
    132  
    133             e.QueryResult = true;  
    134  
    135             if (e.Options.Status == DragStatus.DragQuery)  
    136             {  
    137                 e.Options.SourceCueHost = null;  
    138                 e.Options.Payload = box.SelectedItem;  
    139                 ContentControl cue = new ContentControl();  
    140                 cue.ContentTemplate = this.Resources["ApplicationDragTemplate"as DataTemplate;  
    141                 cue.Content = box.SelectedItem;  
    142                 e.Options.DragCue = cue;  
    143                 e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue();  
    144             }  
    145         }
    146
    147         #endregion  
    148     }  
    149  
    150     public class ListBoxDataSource : INotifyPropertyChanged  
    151     {
    152         #region Private Instance Variables  
    153  
    154         private Guid _Id;  
    155         private String _IconPath;  
    156         private String _Name;
    157
    158         #endregion  
    159  
    160         #region Public Property Accessors  
    161  
    162         public Guid Id  
    163         {  
    164             get 
    165             {  
    166                 return this._Id;  
    167             }  
    168             set 
    169             {  
    170                 if (this._Id != value)  
    171                 {  
    172                     this._Id = value;  
    173                     OnPropertyChanged("Id");  
    174                 }  
    175             }  
    176         }  
    177                   
    178         public String IconPath  
    179         {  
    180             get 
    181             {  
    182                 return this._IconPath;  
    183             }  
    184             set 
    185             {  
    186                 if (this._IconPath != value)  
    187                 {  
    188                     this._IconPath = value;  
    189                     OnPropertyChanged("IconPath");  
    190                 }  
    191             }  
    192         }  
    193                   
    194         public String Name  
    195         {  
    196             get 
    197             {  
    198                 return this._Name;  
    199             }  
    200             set 
    201             {  
    202                 if (this._Name != value)  
    203                 {  
    204                     this._Name = value;  
    205                     OnPropertyChanged("Name");  
    206                 }  
    207             }  
    208         }
    209
    210         #endregion  
    211  
    212         #region Constructors  
    213  
    214         public ListBoxDataSource(Guid id, String name)  
    215         {  
    216             this._Id = id;  
    217             this._Name = name;  
    218             this._IconPath = "../../Images/NoIcon.png";  
    219         }  
    220  
    221         public ListBoxDataSource(Guid id, String name, String iconPath) : this(id, name)  
    222         {  
    223             this._IconPath = iconPath;  
    224         }
    225
    226         #endregion  
    227  
    228         #region Public Events  
    229  
    230         /// <summary>  
    231         /// Raised when the value of one of the properties changes.  
    232         /// </summary>  
    233         public event PropertyChangedEventHandler PropertyChanged;
    234
    235         #endregion  
    236  
    237         #region Protected Event Handlers  
    238  
    239         /// <summary>  
    240         /// Called when the value of a property changes.  
    241         /// </summary>  
    242         /// <param name="propertyName">The name of the property that has changed.</param>  
    243         protected virtual void OnPropertyChanged(String propertyName)  
    244         {  
    245             if (String.IsNullOrEmpty(propertyName))  
    246                 return;  
    247               
    248             if (PropertyChanged != null)  
    249                 PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));  
    250         }
    251
    252         #endregion  
    253     }  
    254 }  
    255  

    Here's the code that renders the AssignedItemsWindow control:
    1 private void RenderAssignedItemsWindow()  
    2 {  
    3     // Create a new instance of AssignedItemsWindow  
    4     AssignedItemsWindow AIW = new AssignedItemsWindow()  
    5
    6     // Wire up Drop Events  
    7     AIW.dlbAssignedItems.DropInfo += new EventHandler<Telerik.Windows.Controls.DragDrop.DragDropEventArgs>(dlbAssignedItems_DropInfo);  
    8     AIW.dlbUnassignedItems.DropInfo += new EventHandler<Telerik.Windows.Controls.DragDrop.DragDropEventArgs>(dlbUnassignedItems_DropInfo);  
    9     AIW.miAssignAll.Click += new RoutedEventHandler(miAssignAll_Click);  
    10     AIW.miUnassignAll.Click += new RoutedEventHandler(miUnassignAll_Click);  
    11  
    12     // Bind the appropriate ObservableCollections to the AssignedItemsWindow's Draggable List Boxes  
    13     AIW.dlbAssignedItems.ItemsSource = *** Some List *** 
    14     AIW.dlbUnassignedItems.ItemsSource = *** Some List ***
    15  
    16     // Add the AssignedItemsWindow to this control  
    17     LayoutRoot.Children.Add(AIW);  
    18  
    19     // Render the AssignedItemsWindow in Dialog (Modal) mode  
    20     AIW.winItems.ShowDialog();  
    21

    Here's the code to perform some action on the DropInfo event:
    1 protected void dlbAssignedItems_DropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e)  
    2 {  
    3     ///Perform some action  
    4 }  
    5  
    6 protected void dlbUnassignedItems_DropInfo(object sender, Telerik.Windows.Controls.DragDrop.DragDropEventArgs e)  
    7 {  
    8     ///Perform some action  
    10

    Hopefully this helps.
  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 07 Jul 2009 Link to this post

    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.
  6. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 15 Jul 2009 Link to this post

    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.
  7. Yuri Brutyan
    Yuri Brutyan avatar
    5 posts
    Member since:
    Feb 2010

    Posted 24 Feb 2010 Link to this post

    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
  8. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 26 Feb 2010 Link to this post

    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.
Back to Top
DevCraft banner