TreeViewDragDropTarget перемещает, но не копирует - PullRequest
4 голосов
/ 25 ноября 2010

У меня есть элемент управления TreeView с его ItemsSource, связанным с ObservableCollection моей ViewModel.У меня есть TreeView, обернутый TreeViewDragDropTarget, так что пользователи могут перемещать узлы дерева вокруг, а именно Windows Explorer.

У меня TreeViewDragDropTarget AllowedSourceEffects установлен на Копировать, Переместить.

Hoverver независимо отпользователь, выполняющий действие копирования (перетаскивание с нажатой клавишей CTRL), остается движением.События ObservableCollection CollectionChanged запускаются сначала с помощью Remove, а затем Add.То, на что я бы надеялся, это просто Add.

Вот Xmal.Чего мне не хватает?

<UserControl x:Class="TreeViewDragDrop.MainPage"
    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:local="clr-namespace:TreeViewDragDrop"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="800" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
    <UserControl.Resources>
        <local:MainPageViewModel x:Key="ViewModel"/>
        <sdk:HierarchicalDataTemplate x:Key="PeopleTemplate" ItemsSource="{Binding Children}">
            <TextBlock Text="{Binding Name}"/>
        </sdk:HierarchicalDataTemplate>
    </UserControl.Resources>
    <Canvas x:Name="LayoutRoot" DataContext="{StaticResource ViewModel}">
        <toolkit:TreeViewDragDropTarget AllowDrop="True" AllowedSourceEffects="Copy,Move" >
            <sdk:TreeView Margin="0" Width="250" ItemsSource="{Binding People}" ItemTemplate="{StaticResource PeopleTemplate}"/>
        </toolkit:TreeViewDragDropTarget>
        <sdk:TreeView Margin="270,0" Width="200" ItemsSource="{Binding People}" AllowDrop="True" ItemTemplate="{StaticResource PeopleTemplate}"/>
    </Canvas>
</UserControl>
...