Silverlight工具包。 Treeview拖放功能

时间:2010-07-19 11:42:47

标签: c# .net wpf silverlight

为什么拖放对我的代码不起作用:

   <toolkitDrag:TreeViewDragDropTarget AllowDrop="true" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" BindingValidationError="TreeViewDragDropTarget_BindingValidationError" ItemDroppedOnSource="TreeViewDragDropTarget_ItemDroppedOnSource" ItemDroppedOnTarget="TreeViewDragDropTarget_ItemDroppedOnTarget" ItemDragStarting="TreeViewDragDropTarget_ItemDragStarting">

       <controls:TreeView Name="treeView">

           <controls:TreeView.ItemTemplate>

               <toolkit:HierarchicalDataTemplate ItemsSource="{Binding Children}">

                  <StackPanel Orientation="Horizontal">

                       <TextBlock Text="{Binding Path=FullDescription}" />

                   </StackPanel>

               </toolkit:HierarchicalDataTemplate>

           </controls:TreeView.ItemTemplate>

       </controls:TreeView>

   </toolkitDrag:TreeViewDragDropTarget>

public OrganizationTree()

   {

       InitializeComponent();



       var organizationNodes=new List<OrganizationNode>();

       var firstNode = new OrganizationNode() { FullDescription = "Description" };

       firstNode.Children.Add(new OrganizationNode() { FullDescription = "desc1" });

       firstNode.Children.Add(new OrganizationNode() { FullDescription = "desc2" });

       firstNode.Children.Add(new OrganizationNode() { FullDescription = "desc3" });

       firstNode.Children.Add(new OrganizationNode() { FullDescription = "desc4" });

       organizationNodes.Add(firstNode);

       this.treeView.ItemsSource = organizationNodes;

   }

您是否可以提供一些信息,以便在为treeview设置itemsource时添加拖放功能?

1 个答案:

答案 0 :(得分:0)

我将List改为ObservableCollection,一切都变好了。