TreeViewDragDropTarget不起作用

时间:2011-07-04 08:07:20

标签: silverlight treeview drag-and-drop

Silverlight,工具包

我正在使用TreeViewDragDropTarget。通常,当您拖动项目并将其移动到另一个项目上时,所选项目的上下箭头将更改为右箭头。

在我的情况下,它不会被更改,拖放也不起作用。

TreeView:

<controlsToolkit:TreeViewDragDropTarget Grid.Row="2" AllowDrop="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" >
    <controlsToolkit:TreeViewDragDropTarget.Resources>
        <Data:HierarchicalDataTemplate x:Key="FilterableTreeViewTemplate" ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal" Height="Auto" Width="Auto">
                <Image Source="{Binding NodeType,Converter={StaticResource TreeIconConverter}}" />
                <TextBlock x:Name="NameTextBlock" Text="{Binding Name}" />
            </StackPanel>
        </Data:HierarchicalDataTemplate>
    </controlsToolkit:TreeViewDragDropTarget.Resources>
    <Controls:TreeView Name="treeView" ItemTemplate="{StaticResource FilterableTreeViewTemplate}" ItemsSource="{Binding ElementName=MyFilterableTreeViewControl, Path=ItemsSource}" SelectedItemChanged="treeView_SelectedItemChanged"/>
</controlsToolkit:TreeViewDragDropTarget>

ItemsSource:

public ObservableCollection<IFilterableTreeViewItem> ItemsSource 
{
    get { return ( ObservableCollection<IFilterableTreeViewItem> )GetValue( ItemsSourceProperty ); }
    set { SetValue( ItemsSourceProperty, value ); }
}

public static readonly DependencyProperty ItemsSourceProperty =
    DependencyProperty.Register( "ItemsSource", typeof( ObservableCollection<IFilterableTreeViewItem> ), typeof( FilterableTreeViewControl ),
    new PropertyMetadata( null, new PropertyChangedCallback( FilterableTreeViewControl.OnItemsSourcePropertyChange ) ) );

private static void OnItemsSourcePropertyChange( DependencyObject d, DependencyPropertyChangedEventArgs e ) 
{
    FilterableTreeViewControl ctrl = d as FilterableTreeViewControl;
            ctrl.OnItemsSourceChange( ( ObservableCollection<IFilterableTreeViewItem> )e.NewValue );
}

protected virtual void OnItemsSourceChange( ObservableCollection<IFilterableTreeViewItem> NewItemsSource ) 
{
    UpdateTreeViewItemsSource( NewItemsSource );
}

有什么想法吗?


如果我删除了ItemTemplate,而不是“works”。


我发现while dragging, I don't see helper-lines in Silverlight

但在我的情况下,这两种类型是相同的:ObservableCollection<IFilterableTreeViewItem>

1 个答案:

答案 0 :(得分:0)

这是解决方案: http://www.codeproject.com/KB/silverlight/HierarchicalDataTemplate.aspx

我还需要一个TreeNode抽象级别。