Hello,
I am currently trying to combine two collections into one for binding to a combobox. I first started out with two static collections built within a class:
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" };
}
The above works as desired. What I would like to do now is to initate a query to a service and have the results of that service appended to the collection instead of User1, USer2,USer3
I create a query to the service as:
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?
}
The query works I am just stuck on how to take the results ( e.Results) and bind/concat them to the Items collection. Any pointers or tips would be appreciated.
Note: This is for silverlight so using a composite collections approach does not seem to be an option as the class is not supported.
Thanks in advance