我有以下列表,它是从远程 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”是我想搜索联系人的电话号码,如果找到的话,用联系人姓名替换列表中的号码。
有人可以给我一个示例代码吗?
谢谢!