我有一个带有列表框和组合框的 silverlight 页面...
根据用户在列表框中单击的内容,我想填充下拉框。完成的事件对于列表框中的每个项目都是相同的(项目包括“BaseTypes”、“Bays”、“Face”等)
我怎样才能使完成的方法通用,这样我就不必每次调用都有一个?
private void lstEdits_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ServiceCylinderClient obj = new ServiceCylinderClient();
obj.GetBaysCompleted += new EventHandler<GetBaysCompletedEventArgs>(GetBaysCompleted(this, baysEventArgs));
string selectedItem = lstEdits.SelectedItem as string;
switch selectedItem
{
case "BaseTypes":
obj.GetBaseTypesCompleted += new EventHandler<GetBaseTypesCompletedEventArgs>(GetBaysCompleted(this, baysEventArgs));
obj.getGetBaseTypesAsync();
break;
case "Bays":
obj.GetBaysCompleted += new EventHandler<GetBaysCompletedEventArgs>(GetBaysCompleted(this, baysEventArgs));
obj.getGetBaysAsync();
break;
}
}
就目前而言,每次调用我都必须有一个“完成的方法”,但是因为它们都会做同样的事情(只需设置列表框项目源)..我想让它通用以简化事情.
void GetBaseTypesCompleted(object sender, getBaseTypesCompletedEventArgs e)
{
lstEdits.ItemsSource = e.Result;
}
void GetBaysCompleted(object sender, getBaysCompletedEventArgs e)
{
lstEdits.ItemsSource = e.Result;
}
提前致谢!