如何在WPF中创建可编辑的树形列表视图?

4

我需要为我的项目创建一个可编辑的TreeListView。但是据我所知,WPF没有提供任何类型的树形列表视图,而我在网上找到的那些也不是很有用。我想使用Blend创建一些东西,然后将其应用到我的WPF项目中。

有人有什么想法吗?

谢谢。


可编辑是指什么?那么Microsoft.com上的那个呢?http://msdn.microsoft.com/en-us/library/vstudio/ms771523(v=vs.90).aspx - Nikhil Agrawal
@NikhilAgrawal 我之前就看过那个链接,但它并没有提供太多帮助。我需要使用Blend进行自定义,但是我无法使用这个工具来实现。你知道怎么做吗?谢谢。 - Ximbalimba
1
在WPF中,一切都是可编辑的。您只需要提供一个适当的“DataTemplate”。发布您所需的屏幕截图,我可以告诉您如何操作。 - Federico Berasategui
@HighCore 我同意你的观点,但我认为OP更关心树形列表本身。我自己也遇到了这个问题。Ximbalimba 你已经在Blend中有一些项目了吗?这就是你需要它的原因吗? - eestein
@eestein 是的,我有。我已经在 Blend 中完成了这个。 - Ximbalimba
1个回答

0

我之前用过类似的方法,也许这能帮你找到一个解决方案。

<dxg:GridControl Name="GridName" Grid.Row="0">

<dxg:GridControl.Columns>

    <dxg:GridColumn FieldName="ID" Header="ID" 
                    AllowEditing="false" 
                    AllowMoving="False" AllowGrouping="False" AllowSorting="False"
                    >
    </dxg:GridColumn>

    <dxg:GridColumn Name="Name" FieldName="Name" Header="Name" AllowEditing="true"
                    AllowMoving="False" AllowGrouping="False" AllowSorting="False" >
    </dxg:GridColumn>

</dxg:GridControl.Columns>

<dxg:GridControl.View>
    <dxg:TreeListView Name="TreePeople" AutoWidth="True"
        KeyFieldName="Id" ParentFieldName="ParentId"
        TreeDerivationMode="Selfreference"
        MultiSelectMode="Row" EditorShowMode="MouseUpFocused" ShowingEditor="TreePeople_ShowingEditor" CellValueChanging="TreePeople_CellValueChanging" >
        <dxg:TreeListView.RowCellMenuCustomizations>
            <dxb:BarButtonItem BarItemName="btnAddRow"  />
            <dxb:BarButtonItem BarItemName="btnRemoveRow"  />
        </dxg:TreeListView.RowCellMenuCustomizations>
    </dxg:TreeListView>
</dxg:GridControl.View>

<i:Interaction.Behaviors>
    <dxg:TreeListDragDropManager AllowDrag="True" AllowDrop="True" AllowAutoExpand="True" Drop="TreeListDragDropManager_Drop" Dropped="TreeListDragDropManager_Dropped" />
</i:Interaction.Behaviors>

在开始之前,您需要初始化一个列表。

public void constructor()
{
    try
    {
        IPeople cli = ProxyFactory.GetPeopleSvc();
        List<People> list = cli.GetClassification();

        if (list.count > 0)
        {
            ObservableCollection<People> tmp = new ObservableCollection<People>(list);
            GridName.ItemsSource = tmp;
        }
    }
    catch (Exception e)
    {
        Message.Show(e);
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接