所以我有一个简单的设置,一个带有我想绑定(bind)到命令的填充事件的自动完成框。我用
clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity
(有更好的命名空间吗?)
绑定(bind)它没什么大不了的,重要的是将 PopulatingEventArgs 参数传递给绑定(bind)的命令。
那么我该如何根据特别是 PRISM 和一般 MVVM 的最佳实践来做到这一点?
最佳答案
我尝试了 InteractiveCommand,它给我带来了问题。相反,我设置了对 Microsoft.Expression.Interactions 的引用并包含
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
<i:Interaction.Triggers>
<i:EventTrigger EventName="AppointmentEditing">
<ei:CallMethodAction MethodName="AppointmentEditing" TargetObject="{Binding}" />
</i:EventTrigger>
<i:EventTrigger EventName="ShowDialog">
<ei:CallMethodAction MethodName="ShowDialog" TargetObject="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
...在我的用户控件中。
然后将事件处理程序放入我的 ViewModel 并将范围设置为公共(public):
public void ShowDialog(object sender, ShowDialogEventArgs e) {
}
public void AppointmentEditing(object sender, AppointmentEditingEventArgs e) {
}
目前运行良好。
关于c# - 如何使用触发器将事件参数传递给命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13565484/