Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF treeview添加到列表框_C#_Wpf_Xaml_Listbox_Treeview - Fatal编程技术网

C# WPF treeview添加到列表框

C# WPF treeview添加到列表框,c#,wpf,xaml,listbox,treeview,C#,Wpf,Xaml,Listbox,Treeview,我正在做一个小的WPF项目,需要将treeview节点添加到listbox,目前我有绑定数据到我的treeview: <Window.Resources> <HierarchicalDataTemplate DataType="{x:Type data:Category}" ItemsSource="{Binding Path=Products}"> <TextBlock Text="{Binding Path=CategoryNam

我正在做一个小的WPF项目,需要将treeview节点添加到listbox,目前我有绑定数据到我的treeview:

    <Window.Resources>
    <HierarchicalDataTemplate DataType="{x:Type data:Category}" ItemsSource="{Binding Path=Products}">
        <TextBlock Text="{Binding Path=CategoryName}" AllowDrop="True"/>
    </HierarchicalDataTemplate>
    <HierarchicalDataTemplate DataType="{x:Type data:Product}" >
        <TextBlock Text="{Binding Path=ModelName}" AllowDrop="True"/>
    </HierarchicalDataTemplate>
</Window.Resources>
<TreeView x:Name="tv_Project" Margin="5" />

但是我不知道如何编写将treeview节点添加到listbox的代码,通常应用程序会单击:右键单击treeview节点将其添加到listbox(或直接将treeview节点拖动到listbox),希望我能清楚地解释我的问题,谢谢

类别和产品是否有不同的列表框,或者使用相同的列表框?只有一个列表框可以有一个列表框来显示字符串列表。这些字符串可以是类别和模型的名称。现在,在树视图节点上添加上下文菜单。单击鼠标右键,关联菜单将打开,您可以向列表框添加类别或模型。单击上下文菜单,将所选项目添加到列表框项目源。
tv_Project.ItemsSource = App.StoreDb.GetCategoriesAndProducts();