Hi,
I have a TreeView that is bound to multiple view models (different levels of the tree are bound to these models through the use of HierarchicalDataTemplates I list under TreeView.Resources). I found this model here:
I'd love to be able to implement this drag/drop pattern so that I can drag items across two different instances of this tree. I'm having trouble doing so though, because I can’t seem to add attachable properties to my HierarchicalDataTemplate definitions.
Here's my XAML:
<TreeView ItemsSource="{Binding Directories}"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True">
<TreeView.ItemContainerStyle>
<!-- bind TreeViewItem to TreeViewItemViewModel-->
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.Resources>
<HierarchicalDataTemplate
DataType="{x:Type local:DirectoryViewModel}"
ItemsSource="{Binding Children}"
<!-I'd like to set dd:DragDrop.IsDragSource/Target to true here, but the dd namespace isn't recognized here-->
>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate
DataType="{x:Type local:WorkspaceFileViewModel}"
ItemsSource="{Binding Children}"
<!-I'd like to set dd:DragDrop.IsDragSource/Target to true here, but the dd namespace isn't recognized here-->
>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate
DataType="{x:Type local:WorkspaceFileElementViewModel}"
ItemsSource="{Binding Children}"
<!-I'd like to set dd:DragDrop.IsDragSource/Target to true here, but the dd namespace isn't recognized here-->
>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Label}" />
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>