【发布时间】:2015-10-21 13:01:18
【问题描述】:
我有一个 moduleA 需要在 moduleB 的 ViewModel 中执行代码。所以我在我的基础设施中创建了一个 commandProxy,并在 moduleB 中注册了一个命令。当我在 proxyCommand 上调用 Execute 时,注册的命令不会执行。应该怎么调试?
模块A
commandProxy.ShowOrderCommand.Execute(""); // I can see the registered command in the debugger
//This is obtained through constructor injection
模块B
showOrderDetailsCommand = new DelegateCommand(() => { }, SubmitAllCanExecute);
commandProxy.ShowOrderCommand.RegisterCommand(showOrderDetailsCommand);
private void ShowOrderDetailsView()
{
_regionManager.RequestNavigate(RegionNames.SecondaryRegion, new Uri("/TradeLogView", UriKind.Relative));
}
基础设施
private static CompositeCommand showOrderDetailsCommand = new CompositeCommand(true);
public class PostMatchCommandProxy
{
virtual public CompositeCommand ShowOrderCommand
{
get { return ShowOrderDetailsCommand; }
}
}
【问题讨论】:
-
你不能用
EventAggregators代替命令。您可以订阅模块 B 中的事件,并在模块 A 需要时发布事件。这比使用命令更容易。