Telerik Forums
UI for Silverlight Forum
16 answers
253 views
Hi After doing a rad controls update from Visual Studio. My drag arrow has disappeared. I am using the following to generate the arrow:

private void OnDragQuery(object sender, DragDropQueryEventArgs e)
 {
// draw the arrow
if (e.Options.Status == DragStatus.DragQuery)
{
e.QueryResult = true;
e.Handled = true;
var arrowCue = RadDragAndDropManager.GenerateArrowCue();
arrowCue.Background = new SolidColorBrush(ColourFormat.GetColourFromHex("#FFCC0000"));
arrowCue.BorderBrush = new SolidColorBrush(ColourFormat.GetColourFromHex("#FFCC0000"));
e.Options.ArrowCue = arrowCue;
}
 }

Telerik Silverlight VSExtensions   2011.01.414.0
Telerik RadControls for Silverlight VSExtensions Package

Martin Ivanov
Telerik team
 answered on 29 Mar 2018
1 answer
87 views

I need to determine if the issue is my version of the implementation of drag/drop or if I am missing something in code.  The version we are using is 2013.3.1204.1050 (I realize it is old however very stable for us).

The issue I am having is on the grid's drag/drop behavior, the TreeViewDragDropOptions returns back as null when dragged from the TreeView to the grid.  I have no idea why when the argument's data property contains the object being dragged over to the grid.  Any help would be appreciative.

XAML:

Resources -

<DataTemplate x:Name="ShiftRouteRun">
    <StackPanel>
        <TextBlock Text="{Binding RouteRunCode}" />
    </StackPanel>
</DataTemplate>
 
<telerik:HierarchicalDataTemplate x:Name="ShiftPlanTemplate"
                                  ItemsSource="{Binding RouteRuns}"
                                  ItemTemplate="{StaticResource ShiftRouteRun}">
    <StackPanel>
        <TextBlock Text="{Binding ShiftTimeDescription}">
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu Opened="RadContextMenu_Opened">
                    <telerik:RadMenuItem Header="Edit" />
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
        </TextBlock>
    </StackPanel>
</telerik:HierarchicalDataTemplate>

 

<telerik:RadTreeView x:Name="tvShifts"
                                     ItemTemplate="{StaticResource ShiftPlanTemplate}"
                                     IsEditable="True"
                                     ItemEditTemplate="{StaticResource ShiftEditTemplate}"
                                     IsDragDropEnabled="True"
                                     Grid.Column="0"
                                     Grid.Row="1" />
 
<telerik:RadGridView x:Name="dgAvailableRuns"
                                     RowStyle="{StaticResource GridDropStyle}"
                                     AllowDrop="True"
                                     AutoGenerateColumns="False"
                                     IsReadOnly="True"
                                     SelectionMode="Single"
                                     ShowGroupPanel="False"
                                     RowIndicatorVisibility="Collapsed"
                                     IsSynchronizedWithCurrentItem="false"
                                     FrozenColumnCount="1"
                                     Height="200"
                                     local:RouteShiftPlanGridViewDropBehavior.IsEnabled="True"
                                     Grid.Column="1"
                                     Grid.Row="1">
                    <telerik:RadGridView.Resources>
                        <DataTemplate x:Key="DragItemTemplate">
                            <StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Dragging:" />
                                    <TextBlock Text="{Binding RouteRunCode}"
                                               FontWeight="Bold" />
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </telerik:RadGridView.Resources>
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn ShowDistinctFilters="False"
                                                    DataMemberBinding="{Binding RouteRunCode}" />
                        <telerik:GridViewDataColumn ShowDistinctFilters="False"
                                                    DataMemberBinding="{Binding SchoolDescription}" />
                        <telerik:GridViewDataColumn ShowDistinctFilters="False"
                                                    DataMemberBinding="{Binding DistrictDescription}" />
                        <telerik:GridViewDataColumn ShowDistinctFilters="False"
                                                    DataMemberBinding="{Binding CalendarDescription}" />
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>

 

Behavior:

Imports Telerik.Windows.Controls
Imports Telerik.Windows.DragDrop
Imports System.Collections
 
''' <summary>
''' For drag/drop handlers on a RadGridView control
''' </summary>
Public Class RouteShiftPlanGridViewDropBehavior
 
    Private _associatedObject As RadGridView
    Private Shared instances As Dictionary(Of RadGridView, RouteShiftPlanGridViewDropBehavior)
 
#Region " Constructors "
    Shared Sub New()
        instances = New Dictionary(Of RadGridView, RouteShiftPlanGridViewDropBehavior)()
    End Sub
#End Region
 
#Region " Public Properties "
    ''' <remarks>For binding to a RadGridView control</remarks>
    Public Shared ReadOnly IsEnabledProperty As DependencyProperty =
        DependencyProperty.RegisterAttached("IsEnabled", GetType(Boolean), GetType(RouteShiftPlanGridViewDropBehavior), New PropertyMetadata(New PropertyChangedCallback(AddressOf OnIsEnabledPropertyChanged)))
 
    ''' <summary>
    ''' AssociatedObject Property
    ''' </summary>
    Public Property AssociatedObject As RadGridView
        Get
            Return _associatedObject
        End Get
        Set(value As RadGridView)
            _associatedObject = value
        End Set
    End Property
#End Region
 
#Region " Methods "
    Public Shared Function GetIsEnabled(obj As DependencyObject) As Boolean
        Return CBool(obj.GetValue(IsEnabledProperty))
    End Function
 
    Public Shared Sub OnIsEnabledPropertyChanged(dependencyObject As DependencyObject, e As DependencyPropertyChangedEventArgs)
        SetIsEnabled(dependencyObject, CBool(e.NewValue))
    End Sub
 
    Public Shared Sub SetIsEnabled(obj As DependencyObject, value As Boolean)
        Dim behavior As RouteShiftPlanGridViewDropBehavior = GetAttachedBehavior(TryCast(obj, RadGridView))
        behavior.AssociatedObject = TryCast(obj, RadGridView)
 
        If value Then
            behavior.Initialize()
        Else
            behavior.CleanUp()
        End If
 
        obj.SetValue(IsEnabledProperty, value)
    End Sub
 
    Private Shared Function GetAttachedBehavior(gridView As RadGridView) As RouteShiftPlanGridViewDropBehavior
        If Not instances.ContainsKey(gridView) Then
            instances(gridView) = New RouteShiftPlanGridViewDropBehavior()
            instances(gridView).AssociatedObject = gridView
        End If
 
        Return instances(gridView)
    End Function
 
    Protected Overridable Sub Initialize()
        UnsubscribeFromDragDropEvents()
        SubscribeToDragDropEvents()
    End Sub
 
    Protected Overridable Sub CleanUp()
        Me.UnsubscribeFromDragDropEvents()
    End Sub
 
    Private Sub SubscribeToDragDropEvents()
        DragDropManager.AddDragInitializeHandler(Me.AssociatedObject, AddressOf OnDragInitialize)
        DragDropManager.AddGiveFeedbackHandler(Me.AssociatedObject, AddressOf OnGiveFeedback)
        DragDropManager.AddDropHandler(Me.AssociatedObject, AddressOf OnDrop)
        DragDropManager.AddDragDropCompletedHandler(Me.AssociatedObject, AddressOf OnDragDropCompleted)
        DragDropManager.AddDragOverHandler(Me.AssociatedObject, AddressOf OnDragOver)
    End Sub
 
    Private Sub UnsubscribeFromDragDropEvents()
        DragDropManager.RemoveDragInitializeHandler(Me.AssociatedObject, AddressOf OnDragInitialize)
        DragDropManager.RemoveGiveFeedbackHandler(Me.AssociatedObject, AddressOf OnGiveFeedback)
        DragDropManager.RemoveDropHandler(Me.AssociatedObject, AddressOf OnDrop)
        DragDropManager.RemoveDragDropCompletedHandler(Me.AssociatedObject, AddressOf OnDragDropCompleted)
        DragDropManager.RemoveDragOverHandler(Me.AssociatedObject, AddressOf OnDragOver)
    End Sub
 
    Private Sub OnDragInitialize(sender As Object, args As DragInitializeEventArgs)
        Dim data As RouteRun = TryCast(DirectCast(args.OriginalSource, FrameworkElement).DataContext, RouteRun)
 
        If data Is Nothing Then
            args.Cancel = True
            Return
        End If
 
        Dim details As New DropIndicatorHelper()
        details.CurrentDraggedItem = data
 
        Dim payload As Telerik.Windows.DragDrop.Behaviors.IDragPayload = Telerik.Windows.DragDrop.DragDropPayloadManager.GeneratePayload(Nothing)
        payload.SetData(GetType(RouteRun), data)
        payload.SetData("DropDetails", details)
 
        Dim visual As New ContentControl()
        With visual
            .Content = data
            .ContentTemplate = TryCast(Me.AssociatedObject.Resources("DragItemTemplate"), DataTemplate)
        End With
 
        args.Data = payload
        args.DragVisual = visual
        args.DragVisualOffset = args.RelativeStartPoint
        args.AllowedEffects = DragDropEffects.All
    End Sub
 
    Private Sub OnGiveFeedback(ByVal sender As Object, ByVal args As Telerik.Windows.DragDrop.GiveFeedbackEventArgs)
        args.SetCursor(Cursors.Hand)
        args.Handled = True
    End Sub
 
    Private Sub OnDrop(sender As Object, e As Telerik.Windows.DragDrop.DragEventArgs)
        Dim options As TreeView.TreeViewDragDropOptions = TryCast(DragDropPayloadManager.GetDataFromObject(e.Data, TreeView.TreeViewDragDropOptions.Key), TreeView.TreeViewDragDropOptions)
        If options Is Nothing Then
            Return
        End If
 
        Dim draggedItem = options.DraggedItems.FirstOrDefault()
        If draggedItem Is Nothing Then
            Return
        End If
 
        If e.Effects <> DragDropEffects.None Then
            Dim collection As IList = TryCast(TryCast(sender, RadGridView).ItemsSource, IList)
            collection.Add(draggedItem)
        End If
 
        e.Handled = True
    End Sub
 
    Private Sub OnDragDropCompleted(sender As Object, e As DragDropCompletedEventArgs)
        Dim draggedItem = DragDropPayloadManager.GetDataFromObject(e.Data, GetType(RouteRun))
 
        If e.Effects <> DragDropEffects.None Then
            Dim collection As IList = TryCast(TryCast(sender, RadGridView).ItemsSource, IList)
            collection.Remove(draggedItem)
        End If
    End Sub
 
    Private Sub OnDragOver(sender As Object, e As Telerik.Windows.DragDrop.DragEventArgs)
        Dim options As TreeView.TreeViewDragDropOptions = TryCast(DragDropPayloadManager.GetDataFromObject(e.Data, TreeView.TreeViewDragDropOptions.Key), TreeView.TreeViewDragDropOptions)
        If options Is Nothing Then
            e.Effects = DragDropEffects.None
            e.Handled = True
            Return
        End If
 
        Dim draggedItem = options.DraggedItems.FirstOrDefault()
        Dim itemsType As Type = TryCast(Me.AssociatedObject.ItemsSource, IList).AsQueryable().ElementType
 
        If draggedItem.[GetType]() IsNot itemsType Then
            e.Effects = DragDropEffects.None
        Else
            TryCast(options.DragVisual, TreeView.TreeViewDragVisual).IsDropPossible = True
            options.DropAction = TreeView.DropAction.Move
            options.UpdateDragVisual()
        End If
 
        e.Handled = True
    End Sub
#End Region
 
End Class
Polya
Telerik team
 answered on 11 Apr 2017
2 answers
95 views
This is what my customers wants from the application. To be able to drag and drop picture files from other applications, the File Explorer or the Desktop, to the SilverLight application. Is that supported?
Pushpendra
Top achievements
Rank 1
 answered on 19 Feb 2016
16 answers
514 views
Hi,

I have this scenario: I have a 2D matrix created by two ItemControls, one is outer for rows, second is a nested and it represent the columns of each row. All it represent a bus seat plan.
Next I have a DataGrid of people and I need to drag & drop items - people between the DataGrid and the ItemsControl matrix.
Is it possible using DragDropBehavior? How to set it?

Thank you

Here is how looks my matrix, the SeatPlan is ObservableCollection<ObservableCollection<Seat>>:
<ItemsControl ItemsSource="{Binding SeatPlan}" >
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Vertical" >
            </StackPanel>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <ItemsControl ItemsSource="{Binding}" >
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal">
                        </StackPanel>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="30" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <TextBox Grid.Column="0"
                               Text="{Binding Label, Mode=TwoWay}" />
                            <TextBox Grid.Column="1"
                               Text="{Binding Descr, Mode=TwoWay}" />
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
Jiri
Top achievements
Rank 1
 answered on 16 Oct 2015
1 answer
54 views

Hello,

sometimes we get a excpetion in the dragdrop hander of the radtreeview, but this is not reproducible.

When this exception happened, I did not explicit drag and drop an item, so i assume I accidentially dragged and droped the same items during clicking (long clicking  and/or mouse moving at the same time)

 

Das Objekt des Typs MS.Internal.ManagedObjectReference kann nicht in Typ System.String umgewandelt werden.
StackTrace:
   bei Telerik.Windows.Controls.RadTreeView.get_TextDropIn()
   bei Telerik.Windows.Controls.TreeView.TreeViewDragDropOptions.GetDropOverItemText(RadTreeViewItem treeViewItem, DropPosition dropPosition)
   bei Telerik.Windows.Controls.TreeView.TreeViewDragDropOptions.UpdateDragVisual()
   bei Telerik.Windows.Controls.RadTreeView.DragDropHelper.OnDragOverItemHandler(Object sender, DragEventArgs e)
   bei Telerik.Windows.DragDrop.DragEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   bei Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   bei Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
   bei Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)
   bei Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
   bei Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)
   bei Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
   bei Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)
   bei Telerik.Windows.DragDrop.DragOperation.RaiseDragEvent(RoutedEvent dragEvent, DependencyObject target)
   bei Telerik.Windows.DragDrop.DragOperation.OnDragOver(DependencyObject sender)
   bei Telerik.Windows.DragDrop.DragOperation.DoDragOver(DependencyObject currentTarget)
   bei Telerik.Windows.DragDrop.DragOperation.OnMove(Point absolutePosition)
   bei Telerik.Windows.DragDrop.DragOperation.DragSourcetPreviewMouseMove(Object sender, MouseEventArgs e)
   bei Telerik.Windows.DragDrop.DragHelper.OnMouseMove(Object sender, MouseEventArgs e)
   bei MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   bei MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)

Milena
Telerik team
 answered on 12 Oct 2015
5 answers
296 views
Hi,

I used a Listbox with a WrapPanel in an ItemsPanelTemplate, like this :

<ListBox x:Name="ProgrammingBox" SelectionMode="Extended">
      <ListBox.ItemsPanel>
               <ItemsPanelTemplate>
                    <toolkit:WrapPanel  />
              </ItemsPanelTemplate>
       </ListBox.ItemsPanel>
</ListBox>

I used the RadDragAndDropManager.

And I want to Drag and Drop multiple items into my Listbox to reorder them. I use the Shift key to select them, but I must stay clicked on my selection to Drag and Drop it. Is it a normal behavior ? Is there a solution to release the mouse click between the selection and the drag and drop ?

Audrey
Dimitrina
Telerik team
 answered on 05 Aug 2015
7 answers
297 views

Hi eveyone,

I think it may be so easy but I don't know how to find the RadlistBoxItem index on which is dropped (DropPosition) in RadListBox before adding the item to destination RadListBox.ItemsSource using DragDropBehavior.

Thank you.

Nasko
Telerik team
 answered on 05 Aug 2015
11 answers
319 views
I have implemented drag&drop like in your example (RadTreeView -> ListBox). This is working but I want not remove element from RTV. Can you help me? Where is the mistake?
Thanks.

MainPage.xaml
<UserControl 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  
    xmlns:dragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls" 
    xmlns:primitives="clr-namespace:Telerik.Windows.Controls.Primitives;assembly=Telerik.Windows.Controls" 
    xmlns:example="clr-namespace:InSEAAtr"  
    x:Class="InSEAAtr.MainPage" 
    mc:Ignorable="d" 
    d:DesignHeight="600" d:DesignWidth="800"
    <UserControl.Resources>        
 
        <LinearGradientBrush x:Key="DropPossibleBackground" StartPoint="0 0" EndPoint="0 1"
            <GradientStop Offset="0" Color="White" /> 
            <GradientStop Offset="1" Color="#FFE699" /> 
        </LinearGradientBrush> 
 
        <telerik:HierarchicalDataTemplate x:Key="CategoryTemplate" ItemsSource="{Binding Items}"
            <StackPanel Orientation="Horizontal"
                <Image Width="16" Height="16" Source="Images/Icons/AtrValidate16.png" 
    Margin="3" VerticalAlignment="Center" /> 
                <TextBlock Text="{Binding Title}" Margin="2" VerticalAlignment="Center" /> 
            </StackPanel> 
        </telerik:HierarchicalDataTemplate> 
 
        <DataTemplate x:Name="ProductTemplate"
            <telerik:RadDockPanel Margin="2" MaxWidth="200"
                <TextBlock Text="{Binding Name}" FontWeight="Bold" telerik:RadDockPanel.Dock="Top" /> 
                <TextBlock Text="{Binding UnitPrice}" Foreground="Green" telerik:RadDockPanel.Dock="Left" /> 
                <TextBlock Text="{Binding Description}" telerik:RadDockPanel.Dock="Left" Margin="2 0 0 0" Foreground="Gray" TextWrapping="Wrap" /> 
            </telerik:RadDockPanel> 
        </DataTemplate> 
 
        <DataTemplate x:Name="MenuTemplate"
            <telerik:RadDockPanel Margin="2" MaxWidth="200"
                <TextBlock Text="{Binding Name}" FontWeight="Bold" telerik:RadDockPanel.Dock="Top" /> 
                <TextBlock Text="{Binding Count}" telerik:RadDockPanel.Dock="Left" /> 
            </telerik:RadDockPanel> 
        </DataTemplate> 
 
        <example:ExampleTemplateSelector x:Key="ExampleTemplateSelector" 
                  CategoryTemplate="{StaticResource CategoryTemplate}" 
                  ProductTemplate="{StaticResource ProductTemplate}" 
                  MenuTemplate="{StaticResource MenuTemplate}"/> 
 
    </UserControl.Resources> 
 
 
 
    <Grid x:Name="LayoutRoot" > 
        <Grid.RowDefinitions> 
            <RowDefinition Height="30"/> 
            <RowDefinition Height="*"/> 
        </Grid.RowDefinitions> 
         
        <Border Grid.Row="0"
            <Border.Background> 
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"
                    <GradientStop Color="#FF828282" Offset="0"/> 
                    <GradientStop Color="#FF585858" Offset="1"/> 
                    <GradientStop Color="#FF4D4D4D" Offset="0.41"/> 
                    <GradientStop Color="#FF232323" Offset="0.431"/> 
                    <GradientStop Color="#FF151515" Offset="0.452"/> 
                    <GradientStop Color="#FF1B1B1B" Offset="0.469"/> 
                </LinearGradientBrush> 
            </Border.Background> 
        </Border> 
        <StackPanel HorizontalAlignment="Left" Margin="4,4,0,4" Orientation="Horizontal"  d:LayoutOverrides="Height"
            <telerik:RadButton x:Name="but3" Content="" Margin="0,0,5,0" Width="22"/> 
            <telerik:RadButton x:Name="but4" Content="" Margin="0,0,5,0" Width="22"/> 
            <telerik:RadButton x:Name="but1" Content="" Margin="0,0,5,0" Width="22"/> 
            <telerik:RadButton x:Name="but2" Content="" Margin="0,0,0,0" Width="22"/> 
        </StackPanel> 
 
        <StackPanel x:Name="spZalogowany" HorizontalAlignment="Center" Margin="0,7" Orientation="Horizontal"
            <sdk:Label x:Name="labLogowanie" d:LayoutOverrides="Height" Foreground="White" Content="Zalogowano: "/> 
            <sdk:Label x:Name="labUser" d:LayoutOverrides="Height" Foreground="White" Content="" ToolTipService.ToolTip="Zalogowany użytkownik"/> 
        </StackPanel> 
        <telerik:RadButton x:Name="butWyloguj" Content="Wyloguj" HorizontalAlignment="Right" Margin="0,4,8,4" d:LayoutOverrides="Height"/> 
 
        <Border Grid.Row="1" Height="30" VerticalAlignment="Top"
            <Border.Background> 
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"
                    <GradientStop Color="#FF828282" Offset="0"/> 
                    <GradientStop Color="#FF585858" Offset="1"/> 
                    <GradientStop Color="#FF4D4D4D" Offset="0.41"/> 
                    <GradientStop Color="#FF232323" Offset="0.431"/> 
                    <GradientStop Color="#FF151515" Offset="0.452"/> 
                    <GradientStop Color="#FF1B1B1B" Offset="0.469"/> 
                </LinearGradientBrush> 
            </Border.Background> 
        </Border> 
 
        <telerik:RadDocking Margin="0,30,0,0" Grid.Row="1" d:LayoutOverrides="Width, Height"
            <telerik:RadDocking.DocumentHost> 
                <telerik:RadSplitContainer> 
                    <telerik:RadPaneGroup> 
                        <telerik:RadPane x:Name="rpGrid" Header="Dokumenty" CanUserClose="False"
                            <telerik:RadGridView/> 
                        </telerik:RadPane> 
                    </telerik:RadPaneGroup> 
                </telerik:RadSplitContainer> 
            </telerik:RadDocking.DocumentHost> 
            <telerik:RadSplitContainer> 
                <telerik:RadPaneGroup SelectedIndex="0"
                    <telerik:RadPane x:Name="rpDrzewo" Header="Menu" CanUserClose="False"
                        <telerik:RadTreeView x:Name="rtvDokumenty" IsLineEnabled="True"  
                                             IsDragDropEnabled="True" ItemTemplateSelector="{StaticResource ExampleTemplateSelector}"
                            <Style TargetType="telerik:RadTreeViewItem"
                                <Setter Property="IsExpanded" Value="True" /> 
                            </Style> 
 
                        </telerik:RadTreeView> 
                    </telerik:RadPane> 
 
                    <telerik:RadPane x:Name="rpSkroty" Header="Moje dokumenty" CanUserClose="False"
                        <ListBox x:Name="lbSkroty" dragDrop:RadDragAndDropManager.AllowDrop="True"
                            <ListBox.ItemTemplate> 
                                <DataTemplate> 
                                    <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Width="100"
                                        
                                        <Image Source="{Binding Icon}" HorizontalAlignment="Center" Width="16" Height="16"/> 
                                        <TextBlock Text="{Binding Name}" FontWeight="Bold"  HorizontalAlignment="Center" 
                                                   TextWrapping="Wrap"/> 
                                        <TextBlock Text="{Binding Count}"  HorizontalAlignment="Center"  
                                                   TextWrapping="Wrap"/> 
                                    </StackPanel> 
                                </DataTemplate> 
                            </ListBox.ItemTemplate> 
                            <ListBox.Style> 
                                <Style TargetType="ListBox"
                                    <Setter Property="dragDrop:RadDragAndDropManager.AllowDrop" Value="True" /> 
                                </Style> 
                            </ListBox.Style> 
                            <ListBox.ItemContainerStyle> 
                                <Style TargetType="Control"
                                   
                                    <Setter Property="dragDrop:RadDragAndDropManager.AllowDrop" Value="True" /> 
                                </Style> 
                            </ListBox.ItemContainerStyle> 
                            <ListBox.ItemsPanel> 
                                <ItemsPanelTemplate> 
                                    <primitives:RadUniformGrid HorizontalAlignment="Center" VerticalAlignment="Top" Columns="1"/> 
                                </ItemsPanelTemplate> 
                            </ListBox.ItemsPanel> 
                        </ListBox> 
                    </telerik:RadPane> 
 
                </telerik:RadPaneGroup> 
            </telerik:RadSplitContainer> 
            <telerik:RadSplitContainer InitialPosition="DockedBottom"
                <telerik:RadPaneGroup SelectedIndex="-1"
                    <telerik:RadPane Header="Pozycja obiegu" x:Name="rpObieg" CanUserClose="False"/> 
                </telerik:RadPaneGroup> 
            </telerik:RadSplitContainer> 
        </telerik:RadDocking> 
 
 
    </Grid> 
</UserControl> 
 

MainPage.cs
using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.Collections.ObjectModel; 
using System.Linq; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Input; 
using System.Windows.Media; 
using Telerik.Windows.Controls; 
using Telerik.Windows.Controls.DragDrop; 
using Telerik.Windows.Controls.TreeView; 
using Telerik.Windows.Controls.Primitives; 
 
namespace InSEAAtr 
    public partial class MainPage : UserControl 
    { 
        //ObservableCollection<RadTreeViewItem> allMenu = Generate(); 
        ObservableCollection<RadTreeViewItem> myMenu; 
 
        public MainPage() 
        { 
            InitializeComponent(); 
 
            rtvDokumenty.Items.Clear(); 
            rtvDokumenty.ItemsSource = CategoryViewModel.Generate(); 
 
 
 
            IList orderSource = new ObservableCollection<MenuViewModel>(); 
 
            lbSkroty.ItemsSource = orderSource; 
 
 
            RadDragAndDropManager.AddDropQueryHandler(lbSkroty, OnDropQuery); 
            RadDragAndDropManager.AddDropInfoHandler(lbSkroty, OnDropInfo); 
            RadDragAndDropManager.AddDragQueryHandler(lbSkroty, OnDragQuery); 
            RadDragAndDropManager.AddDragInfoHandler(lbSkroty, OnDragInfo); 
 
            //demo! 
 
 
 
        } 
         #region demo 
        // OnDragQuery event handler 
        private void OnDragQuery(object sender, DragDropQueryEventArgs e) 
        { 
            System.Windows.Controls.ListBox listBox = sender as System.Windows.Controls.ListBox; 
 
            if (listBox != null
            { 
                IList selectedItems = listBox.SelectedItems.Cast<object>().ToList(); 
                e.Options.Payload = selectedItems; 
            } 
            e.QueryResult = true
            e.Handled = true
        } 
        // OnDropQuery event handler 
        private void OnDropQuery(object sender, DragDropQueryEventArgs e) 
        { 
            ICollection draggedItems = e.Options.Payload as ICollection; 
            bool result = draggedItems.Cast<object>().All((object item) => item is MenuViewModel); 
            e.QueryResult = result; 
            e.Handled = true
        } 
        // OnDragInfo event handler 
        private void OnDragInfo(object sender, DragDropEventArgs e) 
        { 
            System.Windows.Controls.ListBox listBox = sender as System.Windows.Controls.ListBox; 
            IEnumerable draggedItems = e.Options.Payload as IEnumerable; 
            if (e.Options.Status == DragStatus.DragInProgress) 
            { 
                //Set up a drag cue: 
                TreeViewDragCue cue = new TreeViewDragCue(); 
                cue.ItemTemplate = listBox.ItemTemplate; 
                cue.ItemsSource = draggedItems; 
                e.Options.DragCue = cue; 
            } 
            else if (e.Options.Status == DragStatus.DragComplete) 
            { 
                IList source = listBox.ItemsSource as IList; 
                foreach (object draggedItem in draggedItems) 
                { 
                    //source.Remove(draggedItem); 
                } 
            } 
        } 
        // OnDropInfo event handler 
        private void OnDropInfo(object sender, DragDropEventArgs e) 
        { 
            System.Windows.Controls.ItemsControl wishlist = e.Options.Destination as System.Windows.Controls.ItemsControl; 
            ICollection draggedItems = e.Options.Payload as ICollection; 
            if (wishlist == null
                return
            // Get the drag cu that the TreeView or we have created 
            TreeViewDragCue cue = e.Options.DragCue as TreeViewDragCue; 
            if (e.Options.Status == DragStatus.DropPossible) 
            { 
                // Set a suitable text: 
                cue.DragActionContent = String.Format("Dodaj do Moich Dokumentów"); 
                cue.IsDropPossible = true
                wishlist.Background = this.Resources["DropPossibleBackground"as Brush; 
            } 
            else if (e.Options.Status == DragStatus.DropImpossible) 
            { 
                cue.DragActionContent = null
                cue.IsDropPossible = false
            } 
            else if (e.Options.Status == DragStatus.DropComplete) 
            { 
                IList items = wishlist.ItemsSource as IList; 
                foreach (object draggedItem in draggedItems) 
                { 
                    items.Add(draggedItem); 
                } 
 
 
            } 
            if (e.Options.Status != DragStatus.DropPossible) 
            { 
                wishlist.Background = new SolidColorBrush(Colors.White); 
            } 
        } 
        #endregion 
 
    } 
 
 
 
    public class CategoryViewModel 
    { 
        public static IList Generate() 
        { 
            CategoryViewModel fak = new CategoryViewModel(); 
            fak.Title = "Faktury"
            foreach (MenuViewModel item in MenuViewModel.Generate(1)) 
            { 
                fak.Items.Add(item); 
            } 
            CategoryViewModel kor = new CategoryViewModel(); 
            kor.Title = "Korespondencja"
            foreach (MenuViewModel item in MenuViewModel.Generate(2)) 
            { 
                kor.Items.Add(item); 
            } 
            return new ObservableCollection<object>() 
             { 
              fak, kor 
             }; 
        } 
        public CategoryViewModel() 
        { 
            Items = new ObservableCollection<object>(); 
        } 
        public string Title 
        { 
            get
            set
        } 
        public IList Items 
        { 
            get
            set
        } 
    } 
 
    public class ProductViewModel 
    { 
        // Data generation. 
        private static Random generator = new Random(1676545846); 
        private static string[] adjectives = "Fabulous,Amazing,New,Classic,Modern,Durable,Outstanding,Excellent,Premium".Split(','); 
        private static string[] owner = "Alaska,Jonhn,Ray,Ruby,Stone,Lilly,Scott,Barney,Dorian,Neo,Sarah".Split(','); 
        private static string[] objects = "Pen,Manual,Bicycle,Umbrella,Mouse,Vase,Keyboard".Split(','); 
        private static decimal[] prices = { 12.99M, 13.15M, 24.99M, 33.99M, 9.99M, 15.99M, 16.99M, 12.50M }; 
        public static IEnumerable<ProductViewModel> Generate(int count) 
        { 
            for (int i = 0; i < count; i++) 
            { 
                string product = objects[generator.Next(objects.Length)]; 
                ProductViewModel result = new ProductViewModel(); 
                result.Name = String.Format("{0}'s {1} {2}"
                        owner[generator.Next(owner.Length)], 
                        adjectives[generator.Next(adjectives.Length)], 
                        product); 
                result.UnitPrice = prices[generator.Next(prices.Length)]; 
                result.Description = String.Format("Exquisite handcrafted {0}.", product.ToLower()); 
                yield return result; 
            } 
        } 
        public string Name 
        { 
            get
            set
        } 
        public string Description 
        { 
            get
            set
        } 
        public decimal UnitPrice 
        { 
            get
            set
        } 
    } 
 
    public class MenuViewModel 
    { 
        public static List<MenuViewModel> Generate(int count) 
        { 
 
            List<MenuViewModel> result = new List<MenuViewModel>(); 
             
            switch (count) 
            { 
                case 1: 
                    MenuViewModel m2 = new MenuViewModel(); 
                    m2.Count = 2; 
                    m2.Name = "Korespondencja przychodzÄ…ca"
                    m2.Icon = "Images/Icons/AtrValidate16.png"
                    result.Add(m2); 
 
                    MenuViewModel m3 = new MenuViewModel(); 
                    m3.Count = 2; 
                    m3.Name = "Korespondencja wychodzÄ…ca"
                    m3.Icon = "Images/Icons/BUzytkownikUsun16.png"
                    result.Add(m3); 
 
                    break
                case 2: 
 
 
                    MenuViewModel m6 = new MenuViewModel(); 
                    m6.Count = 6; 
                    m6.Name = "Faktury kosztowe"
                    m6.Icon = "Images/Icons/BUzytkownikEdytuj16.png"
                    result.Add(m6); 
 
                    MenuViewModel m1 = new MenuViewModel(); 
                    m1.Count = 6; 
                    m1.Name = "Faktury kosztowe"
                    m1.Icon = "Images/Icons/BUzytkownikHaslo16.png"
                    result.Add(m1); 
 
                    MenuViewModel m4 = new MenuViewModel(); 
                    m4.Count = 2; 
                    m4.Name = "Faktury drobne"
                    m4.Icon = "Images/Icons/BUzytkownikNieaktywni16.png"
                    result.Add(m4); 
                    break
                default
                    break
 
            } 
            return result; 
        } 
 
        public string Name 
        { 
            get
            set
        } 
 
        public int Count 
        { 
            get
            set
        } 
 
        public string Icon 
        { 
            get
            set
        } 
    } 
 
    public class ExampleTemplateSelector : Telerik.Windows.Controls.DataTemplateSelector 
    { 
        public override DataTemplate SelectTemplate(object item, DependencyObject container) 
        { 
            if (item is ProductViewModel) 
                return ProductTemplate; 
            else if (item is CategoryViewModel) 
                return CategoryTemplate; 
            else if (item is MenuViewModel) 
                return MenuTemplate; 
            return null
        } 
        public DataTemplate ProductTemplate 
        { 
            get
            set
        } 
        public DataTemplate CategoryTemplate 
        { 
            get
            set
        } 
 
        public DataTemplate MenuTemplate 
        { 
            get
            set
        } 
    } 
 
Kalin
Telerik team
 answered on 09 Jul 2015
3 answers
68 views
I have a System.Windows.Controls ListBox with a decent number of items within it (say around 50).  I have implemented drag and drop controls with the ListBox through the use of RadDragAndDropManager.  However, the problem we are having is that when a user selects a ListBoxItem and tries to reorder it by dragging it to its desired position, the ListBox scrolls much too quickly to easily and accurately place the dragged item in its desired spot.

It seems like the sensitivity for scrolling the ListBox while dragging an item is too high.  Is there any way to slow down this scrolling behavior for easier drag and drop placement?  Currently, we have instituted buttons to allow for simply moving an item up and down in the ListBox, one row at a time, but that can be tiresome with larger lists of items.
Nasko
Telerik team
 answered on 24 Mar 2015
17 answers
501 views
Is it possible to drop to a DataGridRow. Dropping to a DataGrid works fine but I can't figure out how to determine which row the mouse is over.

Jiri
Top achievements
Rank 1
 answered on 09 Feb 2015
Top users last month
horváth
Top achievements
Rank 2
Iron
Iron
Steve
Top achievements
Rank 2
Iron
Erkki
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 2
Iron
Iron
Veteran
Jakub
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?