0

我有以下列表,它是从远程 XML 填充的

 public class Archive
{
    public string fromsms { get; set; }
    public string sms { get; set; }
    public string tosms { get; set; }
    public string status { get; set; }
    public string date { get; set; }
}

<TextBlock Text="From: " TextAlignment="Left" FontSize="16" Foreground="White" FontWeight="Normal" Grid.Row="0" Grid.Column="0"  HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Text="{Binding fromsms}" TextWrapping="Wrap" FontSize="16" FontWeight="Bold"  Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Text="Date: " FontSize="16" TextWrapping="Wrap" HorizontalAlignment="Right" Grid.Row="0" Grid.Column="2" TextAlignment="Left" Margin="0" />
<TextBlock Text="{Binding date}" FontSize="16" TextAlignment="Left" Foreground="White" FontWeight="Bold" Grid.Row="0" Grid.Column="3" />
<TextBlock Text="To: " TextAlignment="Left" FontSize="16" Foreground="White" Margin="0" Grid.Row="1" Grid.Column="0"/>
<TextBlock Text="{Binding tosms}" TextWrapping="Wrap" FontSize="16" FontWeight="Bold" Grid.Row="1" Grid.Column="1"/>
<TextBlock Text="Status:" FontSize="16" TextWrapping="Wrap" HorizontalAlignment="Right" Grid.Row="1" Grid.Column="2" Margin="0" />
<TextBlock Text="{Binding status}" FontSize="16" TextAlignment="Left" Foreground="White" FontWeight="Bold" Grid.Row="1" Grid.Column="3"/>
<TextBlock Text="{Binding sms}"  FontSize="20" TextWrapping="Wrap" Width="Auto"  Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4"/>

var xmlHistory = XElement.Parse(e.Result);
listbox1.ItemsSource = from history in xmlHistory .Descendants("archive")
select new Archive
{
    fromsms = history.Element("fromn").Value,
    tosms = history.Element("ton").Value,
    status = history.Element("smsstatus").Value,
    date = history.Element("time").Value,
    sms = history.Element("sms").Value,
};

listbox1.Visibility = Visibility.Visible;
PerformanceProgressBar.Visibility = Visibility.Collapsed;

“fromn”和“ton”是我想搜索联系人的电话号码,如果找到的话,用联系人姓名替换列表中的号码。

有人可以给我一个示例代码吗?

谢谢!

4

1 回答 1

0

在这里您可以找到适用于 Windows Phone 平台的代码示例,其中包含有关以下Contacts and Calendar Sample项目和好的主题Contacts API如何:访问 Windows Phone 的联系人数据

升级版:

            ObservableCollection<User> users = new ObservableCollection<User>()
            {
                new User() { phone = "345342645" },
                new User() { phone = "134523534" } ,
                new User() { phone = "345435432" } 
            };

            Contacts contacts = new Contacts();
            contacts.SearchCompleted += (s, e) =>
            {
                var u = (from Contact con in e.Results
                         from ContactPhoneNumber phones in con.PhoneNumbers
                         from user in users
                         where phones.PhoneNumber.Replace("+", "").Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", "").Equals(user.phone)
                         select new User() { name = con.DisplayName, phone = user.phone }).ToList();

                foreach (User user in u)
                {
                    Debug.WriteLine(user.name + " " + user.phone);
                }
            };
            contacts.SearchAsync(String.Empty, FilterKind.None, String.Empty);

接下来是我的User实现:

public class User
{
    public string phone { get; set; }
    public string name { get; set; }
}
于 2012-05-29T17:45:01.043 回答