silverlight 通过 prism 命令,获取事件的事件参数?

发布于 2024-07-25 08:05:37 字数 690 浏览 7 评论 0原文

我在 SL3 中有一个数据表单,它使用带有附加行为的 Prisms 命令来捕获事件。

(它相当严格地遵循这篇博客文章: http://blogs.southworks.net/dschenkelman/2009/04/18/commands-with-attached-behavior-for-silverlight-3-dataform/#comment-607

基本上,一切都连接起来了并且工作正常,但是在视图模型中,我看不到如何访问事件的事件参数。

在 VM 的构造函数中,我定义了委托命令:

this.EditEnded = new DelegateCommand<object>(o => {
    //how can I tell if the button clicked was cancel or save?
}

但我需要访问 DataFormItemEditEndedEventArgs 属性,以便定义需要做什么? 我想根据用户是否取消或提交来执行不同的操作。

I've a data form in SL3 which uses Prisms Commands with Attached Behaviour for trapping events.

(It fairly tightly follows this blog post:
http://blogs.southworks.net/dschenkelman/2009/04/18/commands-with-attached-behavior-for-silverlight-3-dataform/#comment-607)

Basically, it's all hooked up and working fine, however in the viewmodel, I can't see how I can access the event args for the event.

In the constructor of the VM I define the delegate command:

this.EditEnded = new DelegateCommand<object>(o => {
    //how can I tell if the button clicked was cancel or save?
}

But I need access to the DataFormItemEditEndedEventArgs property to so I can define what needs to be done? I want to perform different actions depending if the user cancelled or committed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(2

绮烟 2024-08-01 08:05:38

也许您应该为单独的按钮和操作声明单独的命令(SaveCommand 和 CancelCommand)。

Maybe you should declare seperate Commands (SaveCommand and CancelCommand) for seperate buttons and actions.

剧终人散尽 2024-08-01 08:05:37

要取回参数,您可以像这样编辑 CommandBehaviorBase 派生类:

private void ItemEditEnded(object sender, DataFormItemEditEndedEventArgs e)
{
     this.CommandParameter = e.EditAction;
     ExecuteCommand();
}

这会将 EditAction(或您想要的任何其他内容)发送到 CommandDelegate。 在这种情况下,您不会为参数添加附加属性。 适当地编辑附加的属性类(省略 CommandParameter)。 我不喜欢这种方法(似乎有点不标准),我想知道其他人是否有替代建议。

我的意思是,您始终可以为不同类型的事件添加事件(一个用于提交等),这更纯粹一点,但这意味着需要很多额外的代码。 在这种情况下,你可以逃脱它,但对于其他事件,这将变得不可能(通信鼠标坐标或一些荒谬的事情)。

我的有关 Prism 命令的视频。 处理更多静态参数 有关如何根据静态附加属性对方法进行排序,请参阅“命令参数”部分。

<Button Content="Save"
        HorizontalAlignment="Center"
        VerticalAlignment="Bottom"
        cal:Click.Command="{Binding GetCompanyData}"
        cal:Click.CommandParameter="SaveButton"
        />

To get the parameter back, you could edit your CommandBehaviorBase derived class like this:

private void ItemEditEnded(object sender, DataFormItemEditEndedEventArgs e)
{
     this.CommandParameter = e.EditAction;
     ExecuteCommand();
}

This would send the EditAction (or whatever else you want) to the CommandDelegate. In this case, you would not add an attached property for the parameter. Edit your attached property class appropriately (leave out the CommandParameter). I'm not in love with this approach (seems kinda non-standard), and I wonder if someone else has an alternate suggestion.

I mean, you could always add events for the different kinds of events (one for commit, etc.), and that's a little more pure, but it would mean a lot of extra code. You could get away with it in this instance, but for other events, it would become impossible (communicating mouse coordinates or something ridiculous).

My video on Prism Commands. deals with more static parameters See the "Command Parameters" section for how to sort out the methods based a static attached property.

<Button Content="Save"
        HorizontalAlignment="Center"
        VerticalAlignment="Bottom"
        cal:Click.Command="{Binding GetCompanyData}"
        cal:Click.CommandParameter="SaveButton"
        />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文