如何在Windows Phone 7.1中使用长列表选择器进行分组



要求: -

想要与字母组显示联系人列表。

使用长列表选择器显示联系人列表。在XAML中,我们在长列表选择器中提及用于分组的isflatlist =" false",但它显示了无需组(例如列表框)的联系人列表。

i在此附带您的评论中附加了我的代码,请让我知道我在代码中确实错误的位置。

<phone:PhoneApplicationPage.Resources>
    <!--Heading for the items(a,b,c,d) -->
    <DataTemplate x:Key="GroupItemHeaderTemplate">
        <Border Background="Transparent" Padding="5">
            <Border Background="{StaticResource PhoneAccentBrush}" BorderBrush="{StaticResource PhoneAccentBrush}" BorderThickness="2" Width="480" Height="40" Margin="0,0,18,0" HorizontalAlignment="Left">
                <TextBlock Text="{Binding Key}" Foreground="{StaticResource PhoneForegroundBrush}" FontSize="20" Padding="6" FontFamily="{StaticResource PhoneFontFamilySemiLight}" HorizontalAlignment="left" VerticalAlignment="Center"/>
            </Border>
        </Border>
    </DataTemplate>
    <!-- Heading For the  list -->
    <DataTemplate x:Key="ListHeader">
        <Border Background="#FF049ED6" Height="40">
            <TextBlock Text= "{Binding Key}" />
        </Border>
    </DataTemplate>
    <!--Items to display-->
    <DataTemplate x:Key="ItemTemplate" >
        <StackPanel Orientation="Horizontal">
            <Image Source="{Binding ListImage}" Height="100" Width="100" Stretch="Uniform" Margin="10,2,0,0" ImageFailed="Image_ImageFailed" />
            <TextBlock Text="{Binding ListFullName}" Width="200" Foreground="Black" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22" />
            <TextBlock Text="{Binding ListBio}" FlowDirection="LeftToRight" Foreground="Black" Margin="-200,50,0,0" FontWeight="ExtraLight" FontSize="20" />
        </StackPanel>
    </DataTemplate>
    <!--Group Intems Panel to show when click on Items Header-->
     <ItemsPanelTemplate x:Key="GroupItemsPanel">
        <toolkit:WrapPanel ItemHeight="105" ItemWidth="105"></toolkit:WrapPanel>
     </ItemsPanelTemplate>
 </phone:PhoneApplicationPage.Resources>
<toolkit:LongListSelector x:Name="LongListSelectorListBox" ItemsSource="{Binding Content}" 
                          Margin="0,235,5,104" Width="480" Background="Transparent" IsFlatList="True" 
                          DisplayAllGroups="False" ItemTemplate="{StaticResource ItemTemplate}" 
                          GroupHeaderTemplate="{StaticResource GroupItemHeaderTemplate}" 
                          ListHeaderTemplate="{StaticResource ListHeader}" GroupItemsPanel="{StaticResource GroupItemsPanel}" 
                          SelectionChanged="LongListSelectorListBox_SelectionChanged" />

ViewModel: -

    ServiceModel sm = new ServiceModel();
    Content = new ObservableCollection<ListContactsModel>();
    Content1 = new ObservableCollection<ListContactsModel>();
    ServiceConstants.Temp_Response = x;//Save The response temp
    ObservableCollection<ListContactsModel> result = ListContactsModel.extract(x, sm, OutGoingInvitation);
    ObservableCollection<ListContactsModel> result1 = ListContactsModel.extract(x, sm, IncomeInvitation);
    AppGlobalConstants.Temp_Response = result;
    if (!((string.IsNullOrEmpty(sm.NetErrorCode)) && (string.IsNullOrEmpty(sm.ProvResErrCode))))
    {
        string errCode = !string.IsNullOrEmpty(sm.NetErrorCode) ? sm.NetErrorCode : sm.ProvResErrCode;
        string errDesc = !string.IsNullOrEmpty(sm.NetErrorDesc) ? sm.NetErrorDesc : sm.ProvResErrDesc;
        MessageBox.Show(errCode + "/" + errDesc);
    }else if (result.Count > 0)
    {
        Content.Clear();
        Content1.Clear();
        Content = result;//Outgoing Invitations
        Content1 = result1;//Incoming Invitations
        List<AlphaKeyGroup<ListContactsModel>> DataSource = AlphaKeyGroup<ListContactsModel>.CreateGroups(result,
                                  System.Threading.Thread.CurrentThread.CurrentUICulture,
                                  (ListContactsModel s) => { return s.ListFullName; },
                                  true);
        Console.WriteLine("Content.Count==>>" + Content.Count);
        Console.WriteLine("DataSource.ElementAt(1).Key==>>" + DataSource.ElementAt(1).Key);
        Console.WriteLine("DataSource.ElementAt(2).Key==>>" + DataSource.ElementAt(2).Key);

问候,Naresh T

我看不到整个代码,我不知道什么是ListContactsModel。它是一个集合(从iEnumerable/list/...继承)吗?它有项目的物品吗?它有getEnumerator方法吗?

据我了解,据我了解,从这里取了AlphakeyGroup类(,如果没有,请先阅读)(v = vs.105).aspx

因此,也许您想将longlistector绑定到某些属性,这些属性从 dataSource 接收数据,并且具有相同的类型 list&lt; _alphakeyGroup&lt>/strong>(不内容)?

这是关于长列表的几篇文章:

  • http://www.geekchamp.com/articles/wp7-longlistector-in-depth--part1-bart1-visual-sstructure-and-api
  • http://www.geekchamp.com/articles/wp7-longlistector-in-depth-part-part2-data-data-binding-scenarios(这对您来说很棒)

首先,按照说明。

在LLS中的一般分组中,您有收集的项目,由键/标题/标题/newer和组的内部集合组成。

最新更新