2009-07-14 32 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不會顯示出來。