TreeViewDragDropTarget移动但不复制

时间:2010-11-25 14:40:45

标签: silverlight silverlight-toolkit

我有一个TreeView控件,它的ItemsSource绑定到我的ViewModel的ObservableCollection。我有一个由TreeViewDragDropTarget包装的TreeView,因此用户可以移动树的节点,例如Windows资源管理器。

我将TreeViewDragDropTarget AllowedSourceEffects设置为Copy,Move。

Howerver无论用户执行复制操作(按住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>

0 个答案:

没有答案