2011-06-10 101 views
1

我有一个绑定到数据库表的树形视图。每个treeview项目都是一个网格,它将在第一列中显示一个显示名称,然后是包含文本框的可变数量的列(这将取决于在其中一列中找到的不同值的数量)。我听说一个自定义控件将是一个很好的选择来完成这个任务,但即使在网上看了一些教程之后,我也很难找出从哪里开始。动态创建WPF网格

谢谢!

+0

我假设这与[你的其他问题](http://stackoverflow.com/questions/6140783/wpf-programmatically-create-treeview-itemtemplate-columns)有关。我将使用ItemsControl来代替Grid,但这需要TreeViewItem的DataContext(一个SubOrganLocation?)可以提供某种枚举类型。你可以提供有关TreeViewItem绑定的对象的更多信息吗? – 2011-06-10 18:53:05

+0

@ default.kramer是的,这个问题有点相关。 SubOrganLocations是具有4个字段的对象的ObservableCollection(3个字符串,1个具有4个附加字段的其他对象 - 1个int,3个字符串) – Saggio 2011-06-10 19:33:28

回答

0

你应该先使用HierarchicalDataTemplate这样的:

<HierarchicalDataTemplate ItemsSource="{Binding YourDataTimeChildNodes}" DataType="{x:Type YourDataType}"> 
    <Grid> 
      <TextBlock Text={Binding YourData}/> 
      <TextBox Text={Binding YourData2}/> 
      And other stuff 
    </Grid> 
</HierarchicalDataTemplate>