Allow Drag and Drop, Prevent reorder

3 posts, 0 answers
  1. Patrick
    Patrick avatar
    55 posts
    Member since:
    Jun 2008

    Posted 10 Aug Link to this post

    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. Nasko
    Admin
    Nasko avatar
    585 posts

    Posted 15 Aug Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Patrick
    Patrick avatar
    55 posts
    Member since:
    Jun 2008

    Posted 16 Aug in reply to Nasko Link to this post

    Thanks. Very simple and works.
Back to Top