我想在Windows Phone 8.1中开发类似Longlist Selector Wp8的布局。
我遇到了一个问题,我的名单没有出现。
XAML页面
<Grid >
<Grid.Resources>
<CollectionViewSource x:Name="MainGrps"
IsSourceGrouped="True"/>
</Grid.Resources>
<ListView ItemsSource="{Binding Source={StaticResource MainGrps}}" Margin="50">
<ListView.ItemTemplate>
<DataTemplate >
<Grid Background="Gray">
<StackPanel>
<TextBlock Foreground="White" FontSize="20" Text="{Binding ItmName}"/>
<TextBlock Foreground="White" FontSize="20" Text="{Binding ItmType}"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.GroupStyle>
<GroupStyle HidesIfEmpty="True" >
<GroupStyle.HeaderTemplate>
<DataTemplate >
<Grid Background="Red">
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{Binding GrpItmName}" Foreground="White"/>
<TextBlock Text="{Binding ItemsCount}" Foreground="White"/>
</StackPanel>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</Grid>
代码背后:
private void OnPageLoaded(object sender, RoutedEventArgs e)
{
lst_grp = new List<Grp>();
for (int i = 0; i < 10; i++)
{
Grp grp = new Grp();
grp.GrpItmName = "grp name " + i;
grp.ItemsCount = i;
grp.LstItms = new List<Itm>();
Itm itm = new Itm();
itm.ItmName = "itm name " + i;
itm.ItmType = "itm type " + i;
grp.LstItms.Add(itm);
grp.LstItms.Add(itm);
grp.LstItms.Add(itm);
lst_grp.Add(grp);
}
this.MainGrps.Source = lst_grp;
}
以上代码有问题吗?
请帮我弄明白或建议你是否有工作代码。
答案 0 :(得分:1)
更改
<GroupStyle HidesIfEmpty="True" >
为:
<GroupStyle HidesIfEmpty="False" >
答案 1 :(得分:0)
尝试在ListView标记内的XAML中添加它:
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
或尝试手动设置ListView的宽度和高度参数..只是尝试..
让我知道!