内の項目は、UniformGrid
複数のセルにまたがることはできません。
行/列の高さ/幅がすべて同じサイズになるようにGrid
、代わりに通常の行/列を使用しないのはなぜですか? *
セルを幅と高さが一致する完全な正方形にしたい場合は、グリッドを にバインドするHeight
かWidth
、その逆を行ってください。
アイテムを に追加する前に が各要素を 内にラップするため、グリッド配置プロパティをItemContainerStyle
アイテム自体ではなくに適用する必要があることに注意してください(詳細については、こちらのブログ投稿を参照してください)。ItemsControl
ContentPresenter
ItemsPanel
<ItemsControl ItemsSource="{Binding MyCollection}">
<!-- ItemsPanelTemplate -->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<!-- ItemContainerStyle -->
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Column"
Value="{Binding ColumnIndex}" />
<Setter Property="Grid.Row"
Value="{Binding RowIndex}" />
<!-- Can either use a DataTrigger to determine these values,
or store them on the object itself -->
<Setter Property="Grid.RowSpan"
Value="{Binding RowSpan}" />
<Setter Property="Grid.ColumnSpan"
Value="{Binding ColumnSpan}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>