LongListSelector Windows Phone 8.1

2019-08-13 16:46发布

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 page

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

Code Behind:

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

Is there any problem with above code?

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

2条回答
仙女界的扛把子
2楼-- · 2019-08-13 17:12

Try to add this in the XAML inside the ListView tag:

HorizontalAlignment="Stretch" VerticalAlignment="Stretch"

Or try to set the width and the height parameter of the ListView manually.. Just to try..

Let me know!

查看更多
\"骚年 ilove
3楼-- · 2019-08-13 17:20

Change

<GroupStyle HidesIfEmpty="True" >

to:

<GroupStyle HidesIfEmpty="False" >
查看更多
登录 后发表回答