要求: -
想要显示包含字母组的联系人列表。
使用长列表选择器显示联系人列表。在xaml中,我们在长列表选择器中提到用于分组的IsFlatList =“false”,但它显示的联系人列表没有像列表框这样的组。
我在此附上我的评论代码,请让我知道我在代码中的错误。
<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" />
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
答案 0 :(得分:1)
我没有看到整个代码,我不知道什么是ListContactsModel。它是一个集合(继承自IEnumerable / List / ...)?它有物品吗?它有GetEnumerator方法吗?
据我所知,AlphaKeyGroup类是从这里获取的(如果没有,请先阅读)http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj244365(v=vs.105).aspx
因此,您可能希望将LongListSelector绑定到某些属性,该属性从 DataSource 接收数据并具有相同的类型 List&lt; _AlphaKeyGroup&lt; ListContactsModel &gt; _&gt; (不是内容)?
以下是一些关于LongListSelector的文章:
首先,按照说明进行操作。
一般来说,LLS中的分组意味着你有一些项目集合,包括Key / Title / Header / whatever和group元素的内部集合。