[英]treeview Multibinding in wpf
I want to bind a treeview to a class like this one: 我想将树视图绑定到类似这样的类:
public class Folder : Base_FileFolder
{
public Folder()
{
Folders = new ObservableCollection<Folder>();
Files = new ObservableCollection<File>();
}
public ObservableCollection<Folder> Folders { get; set; }
public ObservableCollection<File> Files { get; set; }
}
the other classes ares: 其他类是:
public class File : Base_FileFolder
{
}
public class Base_FileFolder : DependencyObject
{
public string Name
{
get { return (string)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
public static readonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(string), typeof(Base_FileFolder), new UIPropertyMetadata(""));
}
How can I create a treeview that shows Files and Folders collection 如何创建显示“文件和文件夹”集合的树视图
I want to use something like this: 我想用这样的东西:
<HierarchicalDataTemplate
DataType="{x:Type model:Folder}"
ItemsSource="{Binding Childs}">
<DockPanel>
<Label Content="{Binding Name}"/> </DockPanel>
</HierarchicalDataTemplate>
so I get Somethign like this: 所以我得到像这样的Somethign:
rootFolder 根文件夹
|
|-File
|-File
|-Folder
|-File
|-File
|-Folder
|-File
What exactly is your question? 你究竟是什么问题? How to combine them?
如何结合它们?
CompositeCollection
. CompositeCollection
。
EDIT: as mentioned in the comments, my Intuipic application does something very similar to what you're requesting. 编辑:正如评论中所提到的,我的Intuipic应用程序执行的操作非常类似于您的请求。 Here's a screenshot:
这是一个截图:
This is quite easy, considering your constellation. 考虑到你的星座,这很容易。
First: Adjust your classes. 第一:调整你的课程。 You do not need two separate Lists for files and folders in the folders class.
文件夹类中的文件和文件夹不需要两个单独的列表。 Just use one
IList<Base_FileFolder>
inside the Base_FileFolder class (good OOP) and call it Children! 只需在Base_FileFolder类(好的OOP)中使用一个
IList<Base_FileFolder>
并将其命名为Children!
Then you'll need only two more steps: 然后你只需要两个步骤:
Two HierarchicalDataTemplates 两个HierarchicalDataTemplates
<HierarchicalDataTemplate DataType="{x:Type FolderNode}" ItemsSource="{Binding Path=Children}"> <Grid> <TextBlock Text="{Binding FolderName}" /> </Grid> </HierarchicalDataTemplate> <HierarchicalDataTemplate DataType="{x:Type FileNode}" ItemsSource="{Binding Path=Children}"> <Grid> <TextBlock Text="{Binding FileName}" /> </Grid> </HierarchicalDataTemplate>
And a TreeView like this 还有像这样的TreeView
<TreeView Name="TreeViewFileTree" ItemsSource="{rootFolder.Children}" />
That's it. 而已。 WPF's strength is its simplicity.
WPF的优势在于其简洁性。
You need to use You'll need 3 things: 你需要使用你需要3件事:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.