Fab*_*abi 2 c# wpf xaml itemscontrol
我已经尝试通过设置一个带有和作为属性的网格来将 aListView
和 an 的子项ItemsControl
放在行和列中。RowDefinitions
ColumnDefinitions
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>
Run Code Online (Sandbox Code Playgroud)
我怎样才能使这项工作?谢谢你。
您应该设置包装根元素的容器的属性Grid.Row
和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>
Run Code Online (Sandbox Code Playgroud)