长列表选择器 Windows Phone 8.1 [英] LongListSelector Windows Phone 8.1

查看:25
本文介绍了长列表选择器 Windows Phone 8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Windows phone 8.1 中开发一个类似 Longlist Selector Wp8 的布局.

I wanted to Develop a similar layout like Longlist Selector Wp8 in Windows phone 8.1.

我遇到了一个问题,我的列表没有出现.

I came across a issue, my list is not appearing.

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;
    }

上面的代码有问题吗?

请帮我弄清楚或建议您是否有工作代码.

Please help me to figure it out or suggest if you have working code.

推荐答案

更改

<GroupStyle HidesIfEmpty="True" >

到:

<GroupStyle HidesIfEmpty="False" >

这篇关于长列表选择器 Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆