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

Allow Drag and Drop, Prevent reorder

2 Answers 302 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Datafyer
Top achievements
Rank 1
Veteran
Datafyer asked on 11 Aug 2016, 12:20 AM

I have a RadListBox that I am dragging items to a RadDiagram. This part works, but I can't figure out how to prevent reorder from within the RadListBox. I have tried several things. I just want to prevent the horizontal line from showing when the item is dragged away from the listboxand move to a different position within the list box.

 

This is my current code.

Xaml (Simplified to focus on problem)

01.<UserControl>
02.    <UserControl.Resources>
03.        <Style x:Key="DraggableListBoxItem" TargetType="telerik:RadListBoxItem" BasedOn="{StaticResource RadListBoxItemStyle}">
04.            <Setter Property="telerik:DragDropManager.AllowDrag" Value="True" />
05.        </Style>
06.    </UserControl.Resources>
07. 
08.    <Grid Margin="5">
09.        <Grid.ColumnDefinitions>
10.            <ColumnDefinition Width="Auto" />
11.            <ColumnDefinition Width="*" />
12.        </Grid.ColumnDefinitions>     
13. 
14.        <Grid>
15.            <telerik:RadListBox Margin="0 10 0 0" Width="250" Grid.IsSharedSizeScope="True"
16.                            Background="Transparent" ScrollViewer.HorizontalScrollBarVisibility="Disabled" AllowDrop="False"
17.                            ItemContainerStyle="{StaticResource DraggableListBoxItem}"
18.                            ItemsSource="">
19.                <telerik:RadListBox.DragDropBehavior>
20.                    <behaviors:DatasourceDragDropBehavior AllowReorder="False" />
21.                </telerik:RadListBox.DragDropBehavior>
22. 
23.                <telerik:RadListBox.DragVisualProvider>
24.                    <telerik:ScreenshotDragVisualProvider />
25.                </telerik:RadListBox.DragVisualProvider>
26. 
27.                <telerik:RadListBox.ItemTemplate>
28.                    <DataTemplate>
29.                        <Grid>
30.                        </Grid>
31.                    </DataTemplate>
32.                </telerik:RadListBox.ItemTemplate>
33.            </telerik:RadListBox>
34.        </Grid>
35. 
36.        <Grid>
37.            <telerik:RadDiagram IsSnapToGridEnabled="True" BorderThickness="1" BorderBrush="Black">
38.            </telerik:RadDiagram>
39.        </Grid>
40.    </Grid>
41.</UserControl>

Behavior

01.     class DatasourceDragDropBehavior : ListBoxDragDropBehavior
02.    {
03.        public override void DragDropCompleted(DragDropState state)
04.        {
05.            //implement some custom logic here
06.            //Do not call -> base.DragDropCompleted(state);
07.        }
08. 
09.        public override bool CanDrop(DragDropState state)
10.        {
11.            return state.IsSameControl == false;
12.        }
13.    }

2 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 15 Aug 2016, 07:12 AM
Hello Patrick,

In order to prevent the horizontal line from visualization what we could suggest you is to create a custom DropVisualProvider and override the VisualizeDropPlaceholderEnded as demonstrated in the below code-snippet:
<telerik:RadListBox.DropVisualProvider>
    <local:NoDropVisualProvider/>
</telerik:RadListBox.DropVisualProvider>

and:
public class NoDropVisualProvider : LinearDropVisualProvider
{
    public override void VisualizeDropPlaceholderEnded(Telerik.Windows.Controls.RadListBoxItem container, System.Windows.Controls.Panel panel, object dataItem, System.Windows.FrameworkElement dropVisual)
    {
        //base.VisualizeDropPlaceholderEnded(container, panel, dataItem, dropVisual);
    }  
}

We hope this will help you.

Regards,
Nasko
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Datafyer
Top achievements
Rank 1
Veteran
answered on 16 Aug 2016, 10:56 PM
Thanks. Very simple and works.
Tags
ListBox
Asked by
Datafyer
Top achievements
Rank 1
Veteran
Answers by
Nasko
Telerik team
Datafyer
Top achievements
Rank 1
Veteran
Share this question
or