【发布时间】:2010-08-12 14:10:10
【问题描述】:
我目前正在尝试将两个集合合并为一个以绑定到组合框。我首先从一个类中构建的两个静态集合开始:
public partial class MainPage : UserControl
{
//create static observable collection
private ObservableCollection<string> items;
public ObservableCollection<string> Items
{
get
{
return this.items;
}
set
{
if (this.items != value)
{
this.items = value;
}
}
}
protected ObservableCollection<string> StaticItems
{
get
{
return new ObservableCollection<string>() { "Select User", "Select All" };
}
}
//create dynamic observable collection
public MainPage()
{
InitializeComponent();
this.items = this.StaticItems;
this.comboBox1.ItemsSource = this.Items;
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
foreach (var item in GetDynamicItems())
{
this.Items.Add(item);
}
}
private List<string> GetDynamicItems()
{
return new List<string>() { "User1", "User2", "User3" };
}
上面的工作如你所愿。 我现在想做的是启动对服务的查询并将该服务的结果附加到集合而不是 User1、USer2、USer3
我创建了一个对服务的查询:
private void FillOfficerList()
{
QueryClient qc = new QueryClient("BasicHttpBinding_IQuery");
qc.GetOfficerNamesCompleted += new EventHandler<GetOfficerNamesCompletedEventArgs>(qc_GetOfficerNamesCompleted);
qc.GetOfficerNamesAsync();
}
public void qc_GetOfficerNamesCompleted(object sender, GetOfficerNamesCompletedEventArgs e)
{
// Now how do I add e.Results to above collection?
}
查询有效 我只是纠结于如何获取结果 (e.Results) 并将它们绑定/连接到 Items 集合。任何指针或提示将不胜感激。
注意:这是针对 silverlight,因此使用复合集合方法似乎不是一种选择,因为该类不受支持。
提前致谢
【问题讨论】:
标签: c# wpf silverlight collections