I want to drag data from a ListView and drop it in a TreeView(the draging works fine). I use DataBinding and ItemTemplate to fill the TreeView.
<TreeView ItemsSource="{Binding Groups}" Name="tvGroups" AllowDrop="True"
Drop="tvDrop" DragOver="tvDragOver">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Participants}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<Button Tag="{Binding .}" Click="Button_Click_2">
<Image Source="Resources/cross.png" />
</Button>
</StackPanel>
<HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding Alias}" />
<Button Tag="{Binding .}" Name="btnDeleteParticipants" Click="btnParticipants_Click" >
<Image Source="Resources/cross.png" />
</Button>
</StackPanel>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
private void tvDrop(object sender, DragEventArgs e)
{
if (e.Effects == DragDropEffects.Copy &&
e.Data.GetDataPresent(typeof(Participant)))
{
Participant data = e.Data.GetData(typeof(Participant)) as Participant;
}
}
A Participant
is draged from the ListView to the TreeView. Now I need to find the Group
. Any ideas where to get the right Group
from the TreeView?