使用wp8中的电话联系人填充LongListSelector

时间:2015-03-24 12:29:47

标签: windows-phone-8 contacts longlistselector

在我的Windows Phone 8应用程序中,我想用手机的联系人列表填充 LongListSelector 控件,根据DisplayeName进行过滤。怎么做到这一点?

1 个答案:

答案 0 :(得分:0)

这将为您提供所有联系人的完整列表。

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    Contacts cons = new Contacts();
    cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);
    cons.SearchAsync(String.Empty, FilterKind.None, "Contacts Test #1");
}

void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
      this.SessionWeeklyList.ItemsSource = e.Results;
}

使用长列表选择器。

<phone:PhoneApplicationPage.Resources>

    <DataTemplate x:Key="groupHeaderWeeklyTemplate">
        <Border Width="450" Height="72" HorizontalAlignment="Left" Background="Transparent" Margin="6">
            <TextBlock Text="{Binding WeeklyTitle}"
               FontSize="40" Padding="6"
               VerticalAlignment="Center" HorizontalAlignment="Left"
               Foreground="Black" />
        </Border>
    </DataTemplate>

<Style x:Key="LongListSelectorWeeklyJumpListStyle" TargetType="phone:LongListSelector">
        <Setter Property="GridCellSize"  Value="113,113"/>
        <Setter Property="LayoutMode" Value="List" />
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Border Background="CornflowerBlue"
                                    Width="400" Height="65" Margin="6" >
                        <TextBlock Text="{Binding WeeklyTitle}"
                                           FontFamily="{StaticResource PhoneFontFamilySemiBold}"
                                           FontSize="35" Padding="6"
                                           Foreground="White"
                                           VerticalAlignment="Center"/>
                    </Border>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>


<DataTemplate x:Key="SessionWeeklyItemTemplate">
        <StackPanel Orientation="Horizontal" Margin="10,0">
            <StackPanel>
                <TextBlock Text="{Binding Path=SessionTopic}" FontSize="26" />
                <TextBlock Text="{Binding Path=SessionDate}" Style="{StaticResource PhoneTextSubtleStyle}"  />
            </StackPanel>
        </StackPanel>
    </DataTemplate>

<Grid>
                <phone:LongListSelector x:Name="SessionWeeklyList"
                    IsGroupingEnabled="True" LayoutMode="List" HideEmptyGroups="False"
                    ItemTemplate="{StaticResource SessionWeeklyItemTemplate}"
                    GroupHeaderTemplate="{StaticResource groupHeaderWeeklyTemplate}"
                    JumpListStyle="{StaticResource LongListSelectorWeeklyJumpListStyle}"
                    Margin="0,-32,0,32" ScrollViewer.VerticalScrollBarVisibility="Hidden"
                    SelectionChanged="SessionWeeklyList_SelectionChanged_1">
                </phone:LongListSelector>
            </Grid>