在 ExecuteQueryAsync 方法中传递参数。

发布于 2024-11-26 17:01:03 字数 1321 浏览 0 评论 0原文

我有 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在巴黎塔顶看东京樱花 2024-12-03 17:01:04

继承该类,创建一个接受参数的专用实例,参数可以是列表、对象或特定类型的对象。您应该能够将其传入,然后按照您的设想处理结果,因为它具有它期望看到的所有实现并评估为正确的类型。由于这是一个回调,我认为您不需要投射它。

它期望看到:

public virtual void ExecuteQueryAsync(
    ClientRequestSucceededEventHandler succeededCallback,
    ClientRequestFailedEventHandler failedCallback
)

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:

public virtual void ExecuteQueryAsync(
    ClientRequestSucceededEventHandler succeededCallback,
    ClientRequestFailedEventHandler failedCallback
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文