我有ListView
ItemsPanel
,如下所示:
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
对于ListView.View
,我有GridView
个多列。问题是我只能看到第一列中的列标题(UniformGrid
)。我还需要在第二列中显示GridView
的列标题。怎么做?
示例代码:
<ListView>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Day" DisplayMemberBinding="{Binding Day}" />
<GridViewColumn Header="Month" DisplayMemberBinding="{Binding Month}" />
<GridViewColumn Header="Year" DisplayMemberBinding="{Binding Year}" />
</GridView.Columns>
</GridView>
</ListView.View>
<ListView.Items>
<sys:DateTime />
<sys:DateTime />
<sys:DateTime />
</ListView.Items>
</ListView>
答案 0 :(得分:1)
我试图让你期待的外表。所以我做了什么
请随意根据您的使用情况调整样品
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ListView ItemsSource="{Binding}">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Day" DisplayMemberBinding="{Binding Day}" />
<GridViewColumn Header="Month" DisplayMemberBinding="{Binding Month}" />
<GridViewColumn Header="Year" DisplayMemberBinding="{Binding Year}" />
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.Items>
<x:Array Type="{x:Type sys:DateTime}">
<sys:DateTime />
</x:Array>
<x:Array Type="{x:Type sys:DateTime}">
<sys:DateTime />
</x:Array>
<x:Array Type="{x:Type sys:DateTime}">
<sys:DateTime />
</x:Array>
</ItemsControl.Items>
</ItemsControl>
第二种方法
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="Day" Background="LightGray"/>
<TextBlock Text="Month" Grid.Column="1" Background="LightGray"/>
<TextBlock Text="Year" Grid.Column="2" Background="LightGray"/>
<TextBlock Text="{Binding Day}" Grid.Row="1"/>
<TextBlock Text="{Binding Month}" Grid.Column="1" Grid.Row="1"/>
<TextBlock Text="{Binding Year}" Grid.Column="2" Grid.Row="1"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.Items>
<sys:DateTime />
<sys:DateTime />
<sys:DateTime />
</ItemsControl.Items>
</ItemsControl>