我有HeaderedItemsControl
哪个 ItemsSource 绑定到ObservableCollection<Person>
. 我想显示它的内容,例如:
*姓名* Müller Schmid Weber *名字* Peter Hans Willhelm *年龄* 32 56 78 *国家*瑞士奥地利列支敦士登
到目前为止,我的 xaml 代码:
<HeaderedItemsControl ItemsSource="{Binding Path=PersonCollection}">
<HeaderedItemsControl.Template>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="Name"/>
<TextBlock Grid.Column="0" Grid.Row="1" Text="FirstName"/>
<TextBlock Grid.Column="0" Grid.Row="2" Text="Age"/>
<TextBlock Grid.Column="0" Grid.Row="3" Text="Country"/>
<StackPanel Grid.RowSpan="4" Grid.Column="1" Orientation="Horizontal">
<ItemsPresenter/>
</StackPanel>
</Grid>
</ControlTemplate>
</HeaderedItemsControl.Template>
<HeaderedItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="{Binding Path=Name}" />
<Label Grid.Row="1" Content="{Binding Path=FirstName}" />
<Label Grid.Row="2" Content="{Binding Path=Age}" />
<Label Grid.Row="3" Content="{Binding Path=Country}"/>
</StackPanel>
</DataTemplate>
</HeaderedItemsControl.ItemTemplate>
</HeaderedItemsControl>
这给了我类似的东西:
*姓名* 穆勒 施密德 韦伯 *名字*彼得 汉斯 威廉 *年龄* 32 56 78 *国家*瑞士 奥地利 列支敦士登
有没有办法让项目在列中呈现?