我试过把两个孩子ListView
and an ItemsControl
在行和列中,通过设置网格RowDefinitions
and ColumnDefinitions
as the ItemsPanel
财产。
然而,当我输入时,子控件始终与第 1 行和第 1 列对齐
<ItemsControl>
<ItemsControl.ItemsPanel>
<!-- Grid with rows & columns ... -->
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Grid.Row="4" Grid.Column="2" ... />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我怎样才能做到这一点?谢谢。
您应该设置Grid.Row
and Grid.Column
包装根元素的容器的附加属性ItemTemplate
:
<ItemsControl x:Name="iccc">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock>cell 2:2...</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Grid.Row" Value="1" />
<Setter Property="Grid.Column" Value="1" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)