在 ExecuteQueryAsync 方法中传递参数。
我有 Silverlight 应用程序,其中有一些组合框,我想用 SharePoint 列表中的字段名称填充它们。每个ComboBox 都可以具有此列表中的不同字段,例如ComboBoxA 包含用户字段,ComboBoxB 包含数字字段。 现在,我不想为每个 ComboBox 创建不同的 ClientRequestSucceededEventHandler 和 ClientRequestFailedEventHandler 。我也不想“模拟”异步处理。
我的想法是将一些参数传递给这些事件处理程序(例如对目标组合框和项目集合的引用):
void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Context = ClientContext.Current;
//load query for getting user fields
Context.ExecuteQueryAsync(fieldsCallback_Succeeded(cbUserFields, userFields), fieldCallback_Failed);
//load query for getting number fields
Context.ExecuteQueryAsync(fieldsCallback_Succeeded(cbUserFields, numberFields), fieldCallback_Failed);
}
void fieldsCallback_Succeeded(object sender, ClientRequestSucceededEventArgs e)
{
FieldsQueryParams queryParams = sender as FieldsQueryParams;
this.Dispatcher.BeginInvoke(() => queryParams.cbToFill = queryParams.Fields);
}
或者
void fieldsCallback_Succeeded(object sender, ClientRequestSucceededEventArgs e, ComboBox cbToFill, IEnumerable<Field> fields)
{
this.Dispatcher.BeginInvoke(() => cbToFill.ItemsSource = fields);
}
所以问题是:如何将一些参数传递给这些事件处理程序(例如对目标控件的引用)。或者如何通过其他方式解决这个问题?
I have Silverlight app, which has some combo boxes, which I want to fill with fields names from SharePoint list. Every ComboBox can have different fields from this list, e.g. ComboBoxA holds user field and ComboBoxB number fields.
Now, I don't want to create different ClientRequestSucceededEventHandler and ClientRequestFailedEventHandler for every ComboBox. I don't want to "simulate" asynchronous processing either.
My idea was to pass some param to these event handlers (e.g. reference to destination combo box & items collection):
void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Context = ClientContext.Current;
//load query for getting user fields
Context.ExecuteQueryAsync(fieldsCallback_Succeeded(cbUserFields, userFields), fieldCallback_Failed);
//load query for getting number fields
Context.ExecuteQueryAsync(fieldsCallback_Succeeded(cbUserFields, numberFields), fieldCallback_Failed);
}
void fieldsCallback_Succeeded(object sender, ClientRequestSucceededEventArgs e)
{
FieldsQueryParams queryParams = sender as FieldsQueryParams;
this.Dispatcher.BeginInvoke(() => queryParams.cbToFill = queryParams.Fields);
}
OR
void fieldsCallback_Succeeded(object sender, ClientRequestSucceededEventArgs e, ComboBox cbToFill, IEnumerable<Field> fields)
{
this.Dispatcher.BeginInvoke(() => cbToFill.ItemsSource = fields);
}
So the question is: how to pass some param to these event handlers (e.g. reference to destination control). Or how to resolve this problem in other way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
继承该类,创建一个接受参数的专用实例,参数可以是列表、对象或特定类型的对象。您应该能够将其传入,然后按照您的设想处理结果,因为它具有它期望看到的所有实现并评估为正确的类型。由于这是一个回调,我认为您不需要投射它。
它期望看到:
Inherit the class, create a specialized instance that takes arguments, either a list, object or specifically typed objects as you like. You should be able to pass it in and then process the result as you're envisioning since it has all the implementation it expects to see and evaluates to the correct type. Since it's a callback, I don't think you'll need to cast it.
It expects to see: