Drag and Drop Target

May 11, 2010 at 7:16 PM

I tried to get Drag and Drop working between to ListBox Control. But somehow picking up an item is not possible.

Maybe you have a hint for me to get it working

My User Control xaml code looks like this:

<UserControl x:Class="ChatMotion.Views.UserControls.FriendsDD"
    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:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" 
           xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" 
           xmlns:layoutToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
                        xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"                      
           xmlns:win="clr-namespace:System.Windows;assembly=System.Windows.Controls"
    mc:Ignorable="d"
    d:DesignHeight="352" d:DesignWidth="435">
    <UserControl.Resources>
        <DataTemplate x:Key="ItemTemplate">
            <StackPanel Orientation="Horizontal">
                <Image Width="20" Height="20" Source="{Binding Path=pic}"></Image>
                <TextBlock Text="{Binding Path=name}"></TextBlock>
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
    <StackPanel>
        <Grid x:Name="LayoutRoot" Height="352" Width="435">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="300"/>
                <RowDefinition Height="40"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200"/>
                <ColumnDefinition Width="30"/>
                <ColumnDefinition Width="200"/>
                <ColumnDefinition Width="5*" />
            </Grid.ColumnDefinitions>

            <TextBlock Text="All Friends" Grid.Column="0" Grid.Row="0"/>
            <controlsToolkit:ListBoxDragDropTarget Grid.Column="0" Grid.Row="1" AllowDrop="true" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                <ListBox x:Name="FriendsListBox" SelectionMode="Extended" ItemTemplate="{StaticResource ItemTemplate}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox>
            </controlsToolkit:ListBoxDragDropTarget>

            <TextBlock Text="Friends with access to room" Grid.Column="2" Grid.Row="0"/>
            <controlsToolkit:ListBoxDragDropTarget Grid.Column="2" Grid.Row="1" AllowDrop="true" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                <ListBox x:Name="AllowedFriendsListBox" SelectionMode="Extended" ItemTemplate="{StaticResource ItemTemplate}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox>
            </controlsToolkit:ListBoxDragDropTarget>
        </Grid>

    </StackPanel>
</UserControl>

I am binding my first ListBox to a IList of Facebook friend users.

It should be possible to drag and drop friends from one ListBox to the other.

I hope you can help me. Thanks in advance