LongListSelector的Windows Phone 8.1(LongListSelecto

2019-10-23 08:58发布

我想开发在Windows手机8.1类似的布局像Longlist选择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;
    }

有以上代码的任何问题吗?

请帮我弄明白或建议,如果你有工作代码。

Answer 1:

更改

<GroupStyle HidesIfEmpty="True" >

至:

<GroupStyle HidesIfEmpty="False" >


Answer 2:

尝试在ListView标签内的XAML补充一点:

HorizontalAlignment="Stretch" VerticalAlignment="Stretch"

或尝试设置宽度和手动ListView控件的高度参数..只是尝试..

让我知道!



文章来源: LongListSelector Windows Phone 8.1