C# 4.0 我需要在WindowsPhone8中使用列表视图示例程序
我需要在Windows Phone 8中创建一个列表视图,以显示以下调试信息(下面是我当前在C# 4.0 我需要在WindowsPhone8中使用列表视图示例程序,c#-4.0,windows-phone-8,C# 4.0,Windows Phone 8,我需要在Windows Phone 8中创建一个列表视图,以显示以下调试信息(下面是我当前在debug.WriteLine中显示消息的代码) 你们有没有人在这个平台上创建了一个listview并能帮助我?这是我能想到的最简单的例子。 我还添加了对没有任何电话号码的联系人的处理 xaml: 政务司司长: 名称空间so17564250 { 使用System.Collections.ObjectModel; 使用System.Linq; 使用Microsoft.Phone.Controls; 使用
debug.WriteLine
中显示消息的代码)
你们有没有人在这个平台上创建了一个listview并能帮助我?这是我能想到的最简单的例子。
我还添加了对没有任何电话号码的联系人的处理 xaml:
政务司司长:
名称空间so17564250
{
使用System.Collections.ObjectModel;
使用System.Linq;
使用Microsoft.Phone.Controls;
使用Microsoft.Phone.UserData;
公共部分类主页:PhoneApplicationPage
{
公共主页()
{
初始化组件();
this.DisplayedContacts=新的ObservableCollection();
this.DataContext=this.DisplayedContacts;
var触点=新触点();
contacts.SearchCompleted+=(s,e)=>
{
foreach(e.Results中的var触点)
{
此.DisplayedContacts.Add(contact.DisplayName+“-”+
(contact.phonenumber.Any()
?contact.PhoneNumber.First().PhoneNumber
:string.Empty);
}
};
SearchAsync(string.Empty,FilterKind.DisplayName,null);
}
public ObservableCollection DisplayedContacts{get;set;}
}
}
contacts.SearchCompleted += (s, e) =>
{
foreach (var contact in e.Results)
{
Debug.WriteLine(contact.DisplayName + " - " + contact.PhoneNumbers.First().PhoneNumber);
textAddressLine1.Text= contact.DisplayName + " - " + contact.PhoneNumbers.First().PhoneNumber;
}
};
contacts.SearchAsync("", FilterKind.DisplayName, null);
<phone:PhoneApplicationPage
x:Class="so17564250.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="SO 17564250" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="listview example" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<phone:LongListSelector ItemsSource="{Binding}" />
</Grid>
</Grid>
</phone:PhoneApplicationPage>
namespace so17564250
{
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.Phone.Controls;
using Microsoft.Phone.UserData;
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
this.DisplayedContacts = new ObservableCollection<string>();
this.DataContext = this.DisplayedContacts;
var contacts = new Contacts();
contacts.SearchCompleted += (s, e) =>
{
foreach (var contact in e.Results)
{
this.DisplayedContacts.Add(contact.DisplayName + " - " +
(contact.PhoneNumbers.Any()
? contact.PhoneNumbers.First().PhoneNumber
: string.Empty));
}
};
contacts.SearchAsync(string.Empty, FilterKind.DisplayName, null);
}
public ObservableCollection<string> DisplayedContacts { get; set; }
}
}