2009-10-28 28 views

回答

12

好的,在應用Grid.IsSharedSizeScope="true"附屬屬性時使用ItemsControl。接下來,爲您的ItemTemplate中,您使用<Grid>就像你通常會現在除非你添加ColumnDefinition是你的SharedSizeGroup屬性設置爲對每列中唯一的名稱。因此,例如:

<ItemsControl Grid.IsSharedSizeScope="true"> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <Grid> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition SharedSizeGroup="MyFirstColumn" /> 
        <ColumnDefinition SharedSizeGroup="MySecondColumn" /> 
       </Grid.ColumnDefinitions> 
       <TextBlock Grid.Column="0" Text="{Binding MyFirstProperty}"/ > 
       <TextBlock Grid.Column="1" Text="{Binding MySecondProperty}"/ > 
      </Grid> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 

更多關於IsSharedSizeScope和SharedSizeGroup,check out this section of the SDK。應該注意RowDefinitions也有一個SharedSizeGroup,所以你也可以做水平佈局。

+0

是啊......看起來像我要去的路線。 – Rich 2009-10-28 21:16:52

+0

非常有幫助。在相同的情況下(我需要設置'')我也想第二列填充剩餘空間。它的工作,如果我沒有設置'SharedSizeGroup'的第2列:'''''' – ASh 2016-01-18 09:27:31

1

也許我誤解了你的問題,但是這不正是GridView的做法嗎?

+0

謝謝...甚至不知道存在 – Rich 2009-10-28 20:48:49

+0

其實,這並不是我所期待的。我不想要所有額外的花式「數據網格」格式。我不想要列標題,排序功能,默認填充和背景等。我想重複在網格中放置的集合中的項目,就像我通常在ItemsControl中執行的那樣...無非就是。知道什麼? – Rich 2009-10-28 20:57:10

+0

好的...只是爲了確保我明白:你想要水平放置物品而不是垂直放置物品? – 2009-10-28 21:15:32