你如何在城域网应用程序中处理MVVM中的事件?我在
WPF中使用了来自MVVM light的交互类和EventToCommand,但似乎在WinRT中没有交互.也没有触发器所以我必须“使用丑陋的方式”? (代码背后和
(this.DataContext as viewmodel).Command.Execute()
例如?)
解决方法
到目前为止,我发现的EventToCommand的最佳替代方案是附加的命令解决方案,该解决方案已在此
CodeProject article中进行了演示.
这就是它的使用方式.
<Button Content="Test Button" local:AttachedCommand.RoutedEvent="PointerEntered" local:AttachedCommand.Command="{Binding TestCommand}"/>
另一种选择是Joost van Schaik的mimic of the EventToCommand行为,但鉴于所需的依赖性,它对我来说太沉重了.