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

DropPossible & DropImpossible status

1 Answer 110 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tony
Top achievements
Rank 1
Tony asked on 16 Apr 2012, 11:35 PM
Im having an issue where it appears Im getting Drop Possible followed immediately by DropImpossible status. (Note, Im using 2011.3.1220.1040 release and cannot upgrade just yet.)
I have a ListBox with a custom and am trying to allow the user to reorder the items in it by dragging. That all works just fine. However, Im trying to put an indicator in (using the top border of the list box item being drug over) to indicate where the item will be drug too.

When I debug via the output window, I notice that when I drag a ListBoxItem over another ListBoxItem, I get a DragPossible status followed immediately by a DragImpossible status...this of course prevents me from showing the user a DragPossible state visually.  Ive tried adding background colors everywhere as I read that could cause DragImpossible states. Any thoughts? My code is:

<UserControl.Resources>
        <Style x:Key="JobStepsListBoxItemStyle" TargetType="ListBoxItem">
            <Setter Property="telerikPresentation:RadDragAndDropManager.AllowDrag" Value="True"/>
            <Setter Property="telerikPresentation:DragDropManager.AllowCapturedDrag" Value="True" />
            <Setter Property="telerikPresentation:RadDragAndDropManager.AllowDrop" Value="True" />
            <Setter Property="Background" Value="LightYellow" />
            <Setter Property="Template">
                <Setter.Value>
                     
                    <ControlTemplate TargetType="ListBoxItem">
                        <Border BorderBrush="LightYellow" BorderThickness="0 2 0 0" x:Name="indicatorBorder" Background="LightYellow"  Visibility="{Binding IsDeleted, Converter={StaticResource invertBoolToVis}}" >
                            <Grid x:Name="StepRow" Margin="0 0 0 1" Background="LightYellow">
 
                                <Border x:Name="NormalContent" Background="#fff7f7f7" BorderBrush="#ffe1e1e1" BorderThickness="0 1 0 1" Padding="0 5 0 0">
                                    <Grid  Background="LightYellow">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="20" />
                                            <ColumnDefinition Width="5" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="5" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="5" />
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="25" />
                                        </Grid.ColumnDefinitions>
                                         
                                        <!-- Snipped out-->
                                    </Grid>
                                </Border>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
         
        <Style x:Key="ListBoxStyle" TargetType="ListBox" >
            <Setter Property="Padding" Value="0" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="BorderBrush" Value="#FFD6D4D4" />
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <StackPanel>
                            <i:Interaction.Behaviors>
                                <ei:FluidMoveBehavior AppliesTo="Children" InitialTag="DataContext" Tag="DataContext" Duration="0:0:0.5">
                                    <ei:FluidMoveBehavior.EaseY>
                                        <CubicEase EasingMode="EaseOut"/>
                                    </ei:FluidMoveBehavior.EaseY>
                                    <ei:FluidMoveBehavior.EaseX>
                                        <CubicEase EasingMode="EaseOut"/>
                                    </ei:FluidMoveBehavior.EaseX>
                                </ei:FluidMoveBehavior>
                            </i:Interaction.Behaviors>
                        </StackPanel>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemContainerStyle" Value="{StaticResource JobStepsListBoxItemStyle}" />
        </Style>
 
    </UserControl.Resources>
     
     
     
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition />
            </Grid.RowDefinitions>
             
            <!-- Column headers for list of job steps -->
            <Border Background="{StaticResource AppTileBackgroundBrush}" BorderThickness="0" Margin="0" >
                <Grid Grid.Row="0" Margin="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="20" />
                        <ColumnDefinition Width="5" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="5" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="5" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="25" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="#" Grid.Column="0" Foreground="{StaticResource AppTileForegroundBrush}" Margin="5 0 0 0" />
                    <TextBlock Text="Important Step (required)" Grid.Column="2" Foreground="{StaticResource AppTileForegroundBrush}" Margin="5 0 0 0" />
                    <TextBlock Text="Key Point" Grid.Column="4" Foreground="{StaticResource AppTileForegroundBrush}" Margin="5 0 0 0" />
                    <TextBlock Text="Reason" Grid.Column="6" Foreground="{StaticResource AppTileForegroundBrush}" Margin="5 0 0 0" />
                </Grid>
            </Border>
             
            <!-- Job step list -->
            <ListBox x:Name="lstJobSteps"
                 ItemsSource="{Binding JobSteps}"
                 Grid.Row="1"
                 telerik:RadDragAndDropManager.AllowDrop="True"
                 Style="{StaticResource ListBoxStyle}"
                 SelectionMode="Single" />
 
        </Grid>
    </Grid>


Code behind:
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using ECAP.SL.Web.Model;
using ECAP.SL.Transfer.Model;
using ECAP.SL.Web.View.ViewHelpers;
using ECAP.Server.Transfer;
using ECAP.SL.Web.Model.Enumerations;
using GalaSoft.MvvmLight.Messaging;
using Telerik.Windows.Controls.DragDrop;
using System.Collections.Generic;
using System.Windows.Media;
using Telerik.Windows.Controls;
using System.Diagnostics;
 
namespace ECAP.SL.Web.View.Controls
{
    public partial class JISStepsInput : UserControl
    {
 
        public JISStepsInput()
        {
            InitializeComponent();
 
            RadDragAndDropManager.AddDropInfoHandler(this, OnDropInfo);
            RadDragAndDropManager.AddDragQueryHandler(this, OnDragQuery);
            RadDragAndDropManager.AddDragInfoHandler(this, OnDragInfo);
            RadDragAndDropManager.AddDropQueryHandler(lstJobSteps, OnDropQuery);
 
            RadDragAndDropManager.SetAllowDrag(lstJobSteps, true);
            RadDragAndDropManager.SetAllowDrop(lstJobSteps, true);
        }
 
        private void ScrollToLast()
        {
            Dispatcher.BeginInvoke(() => {
                if (lstJobSteps.Items.Count > 0)
                    lstJobSteps.ScrollIntoView(lstJobSteps.Items.Last());
            }
            );
        }
 
        private void OnDropInfo(object sender, DragDropEventArgs e)
        {
            System.Windows.Controls.ListBox box = GetListBox(e.Options.Destination);
            System.Windows.Controls.ListBoxItem destination = null;
            System.Windows.Controls.ListBoxItem source = e.Options.Source as System.Windows.Controls.ListBoxItem;
 
            if (e.Options.Destination is System.Windows.Controls.ListBoxItem) {
                destination = e.Options.Destination as System.Windows.Controls.ListBoxItem;
            }
 
            IList<JISLineItem> itemsSource = box.ItemsSource as IList<JISLineItem>;
            JISLineItem payload = e.Options.Payload as JISLineItem;
 
            if (destination != null) {
                var borderchild = destination.FindChildByType<Border>();
                if (e.Options.Status == DragStatus.DropPossible) {
                    if (source != destination) {
                        borderchild.BorderBrush = new SolidColorBrush(Colors.Red);// listBoxDragPossible;
                        Debug.WriteLine("drop Possible: " + (e.Options.Destination.DataContext as JISLineItem).StepNumber);
                    }
                }
                else {
                    if (source != destination) {
                        borderchild.BorderBrush = new SolidColorBrush(Colors.Cyan);
                        Debug.WriteLine("drop IMPossible: " + (e.Options.Destination.DataContext as JISLineItem).StepNumber);
                    }
                }
            }
 
            if (e.Options.Status == DragStatus.DropComplete) {
                if (!itemsSource.Contains(payload)) {
 
 
                    if (destination != null) {
                        // get payload of listbox item
                        var droppedOntoPayload = destination.DataContext as JISLineItem;
                        int index = itemsSource.IndexOf(droppedOntoPayload);
                        itemsSource.Insert(index, payload);
                    } else
                        itemsSource.Add(payload);
                }
            }
        }
 
        void OnDropQuery(object sender, DragDropQueryEventArgs e)
        {
            System.Windows.Controls.ListBox box = GetListBox(e.Options.Destination);
 
            IList<JISLineItem> itemsSource = box.ItemsSource as IList<JISLineItem>;
            JISLineItem payload = e.Options.Payload as JISLineItem;
 
            e.QueryResult = payload != null;// && !itemsSource.Contains(payload);
        }
 
        void OnDragInfo(object sender, DragDropEventArgs e)
        {
            var listBoxItem = e.Options.Source as System.Windows.Controls.ListBoxItem;
            var box = System.Windows.Controls.ItemsControl.ItemsControlFromItemContainer(listBoxItem) as System.Windows.Controls.ListBox;
            IList<JISLineItem> itemsSource = box.ItemsSource as IList<JISLineItem>;
            JISLineItem payload = e.Options.Payload as JISLineItem;
 
            if (e.Options.Status == DragStatus.DragComplete) {
                if (payload != null && itemsSource.Contains(payload)) {
                    itemsSource.Remove(payload);
                }
            }
        }
 
        protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e)
        {
            var listBoxItem = e.Options.Source as System.Windows.Controls.ListBoxItem;
            var box = System.Windows.Controls.ItemsControl.ItemsControlFromItemContainer(listBoxItem) as System.Windows.Controls.ListBox;
 
            if (e.Options.Status == DragStatus.DragQuery && box != 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.QueryResult = true;
        }
 
        private System.Windows.Controls.ListBox GetListBox(FrameworkElement objDestination)
        {
            if (objDestination is System.Windows.Controls.ListBoxItem)
                return ViewHelper.GetParent(objDestination, typeof(System.Windows.Controls.ListBox)) as System.Windows.Controls.ListBox;
            else
                return objDestination as System.Windows.Controls.ListBox;
 
 
        }
 
 
    }
 
 
}


1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 18 Apr 2012, 11:46 AM
Hello Tony,

The problem is that you have enabled drop both on the listbox items and the listbox itself. The solution that you could do in your case is to remove the allow drop for the listbox. 
It looks like it could be a bug in the RadDragAndDropManager, and we will try to isolate and fix it. However since the it is marked for deprecation(expected Q2 2012), we strongly recommend using the new Drag & Drop mechanism - the DragDropManager.

Hope this helps! If you need any further assistance, please don't hesitate to ask! 

Greetings,
Nik
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
DragAndDrop
Asked by
Tony
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or