2009-07-14 29 views
0

说我有Silverlight 3的DataGrid控件,我想在两行之间动态创建一些空闲空间以显示更多细节。我怎样才能做到这一点?如何在具有不同标题/列布局的Silverlight 3数据网格中动态插入行?

Header1 | Header2 | Header3 | Header4 
------------------------------------- 
Cell1  Cell2  Cell3  Cell4 
Cell5  Cell6  Cell7  Cell8 
Cell9  Cell10 Cell11 Cell12 

例如,将成为:

Header1 | Header2 | Header3 | Header4 
------------------------------------- 
Cell1  Cell2  Cell3  Cell4 
Cell5  Cell6  Cell7  Cell8 
    Foo1 Foo2 
    Foo3 Foo4 
Cell9  Cell10 Cell11 Cell12 

注意两个新插入的“行”,可以有不同的列数,并且可以是不同类型的控件。换句话说,插入的项目可能完全可能是另一个单独的控件。

这甚至可能与DataGrid控件?也许有人有一些聪明的想法。 非常感谢!

回答

0

您将需要一个带有属性的集合类型(即Cell),该集合暴露在单元格中。 (在短手例如属性)

Class Foo 
    Property FooName as String 
End Class 

Class Cell 
    Property CellName as String 
    ReadOnly Property Foos as Generic.List(of Foo) 
End Class 

<DataTemplate x:Key="MyTemplate"> 
    <TextBlock Text={Binding CellName}" /> 
    <StackPanel ItemSource="{Binding Foos}"> 
     <StackPanel.ItemTemplate> 
      <DataTemplate> 
       <TextBlock Text="{Binding FooName}" /> 
      <DataTemplate> 
     <StackPanel.ItemTemplate> 
    </StackPanel> 
</DataTemplate> 

并在您的DataGrid这些单元格,你可以有CellTemplate设置为MyTemplate的。对于具有空Foos集合的单元,Foos不会显示出来。