简体   繁体   English

Catel InterestedIn OnViewModelCommandExecuted检查执行了哪个命令

[英]Catel InterestedIn OnViewModelCommandExecuted check which command executed

I use the Catel 4.3.0 framework . 我使用Catel 4.3.0 framework

I've decorated one of my ViewModels with [InterestedIn(typeof(AddSupplierWindowViewModel))] and added 我已经用[InterestedIn(typeof(AddSupplierWindowViewModel))]装饰了一个ViewModel并添加了

protected override void OnViewModelCommandExecuted(IViewModel viewModel, 
                        ICatelCommand command, object commandParameter)

This event fires correctly. 此事件会正确触发。

In the AddSupplierWindowViewModel I've multiple commands, but only the CmdAddSupplier is of interest to this viewmodel. AddSupplierWindowViewModel我有多个命令,但是此视图模型只对CmdAddSupplier感兴趣。

So I want to check if this command is fired, but I can't figure out how to test for it. 所以我想检查这个命令是否被触发,但是我不知道如何测试它。

I expect something like command.Name == "CmdAddSupplier" but I can't find something like this. 我期望像command.Name == "CmdAddSupplier"这样的东西,但是我找不到这样的东西。

Could someone provide an example of how to test for this. 有人可以提供有关如何对此进行测试的示例。

Kind regards 亲切的问候

Jeroen 耶罗恩

We recommend to use CommandContainers instead of view models to host commands that span more than 1 view model. 我们建议使用CommandContainers而不是视图模型来承载跨越1个以上视图模型的命令。 The InterestedIn communication will probably (most likely) be removed from Catel in v5. 在v5中,有可能(最有可能)从Catel中删除了InterestedIn通信。

Some good examples can be found in the Orchestra repository . Orchestra存储库中可以找到一些很好的例子。

If you really want to keep using the InterestedIn (which is actually a shortcut for setting up services to take care of the communication between the view models), you'll need to figure out how to retrieve the instance (you only get an instance of a command) to a command name. 如果您确实要继续使用InterestedIn(实际上是设置服务以处理视图模型之间的通信的快捷方式),则需要弄清楚如何检索实例(您只能获取的实例)命令)更改为命令名称。 For example, you could use the Tag property on the command. 例如,您可以在命令上使用Tag属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM