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

I can drag but not drop

1 Answer 114 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 12 Dec 2012, 02:18 PM

Dear all,

I want to drag items from one listbox to another. The drag seems to work fine, but the target listbox doesn't get updated with the new item. I do notice that, once dropped, the item is removed from the source list. I try to do stuff declaratively (XAML) as much as I can

Here's the XAML for the enabling of dragging.

<Window.Resources>
        <!-- Make "ViewModel" represent an instance of ViewModel-->
        <local:ViewModel x:Key="ViewModel"/>
        <Style x:Key="DraggableListBoxItem" TargetType="telerik:RadListBoxItem">
            <Setter Property="telerik:DragDropManager.AllowCapturedDrag" Value="True" />
        </Style>
</Window.Resources>

Here's where I display my listboxes

<Grid x:Name="_grid" HorizontalAlignment="Left" Height="436" Margin="10,10,0,0" VerticalAlignment="Top" Width="1297" DataContext="{Binding Source={StaticResource ViewModel}}">
<telerik:RadListBox HorizontalAlignment="Left" Margin="10,48,0,0" VerticalAlignment="Top" Width="106" Height="306" ItemContainerStyle="{StaticResource DraggableListBoxItem}"
ItemsSource="{Binding Segments.AllSegments}" DisplayMemberPath="Code">
<telerik:RadListBox.DragDropBehavior>
<telerik:ListBoxDragDropBehavior />
</telerik:RadListBox.DragDropBehavior>
<telerik:RadListBox.DragVisualProvider>
<telerik:ScreenshotDragVisualProvider />
</telerik:RadListBox.DragVisualProvider>
</telerik:RadListBox>
<telerik:RadListBox HorizontalAlignment="Left" Margin="133,48,0,0" VerticalAlignment="Top" Width="205" Height="306"
ItemsSource="{Binding Segments.SelectedSegments}" DisplayMemberPath="Code" AllowDrop="True">
</telerik:RadListBox>
</grid>
</Window>

For your information: My main ViewModel exposes another viewmodel called Segments which has 2 ObservableCollection<> properties, called AllSegments and SelectedSegments. Both contain the same data type (a viewmodel called Segment).

I was under the impression that I can implement this d&d fully declaratively, since there's no need for data conversion. (Both viewmodels accept the same data type). But the SelectedSegments ObservableCollection is never updated when I drop an item on the target listbox. What am I missing here?

Thanks for responding.

Regards,
~Rob 

1 Answer, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 17 Dec 2012, 09:49 AM
Hi Rob,

If you want to achieve drag and drop between two ListBox controls you will need to declare the DragDropBehavior and ItemContainerStyle on both ListBox controls.

It is worth mentioning that by default the DragVisualProvider of RadListBox is set to ScreenshotDragVisualProvider.

Regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ListBox
Asked by
Rob
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Share this question
or