Prism.Mvvm绑定事件怎样接收object sender, RoutedEventArgs e
时间: 2024-03-11 21:47:26 浏览: 118
rosoft.Press.Developers.Guide.to.Microsoft.Prism.4.Mar.2011
在Prism.Mvvm中,可以使用以下方式绑定事件并接收object sender和RoutedEventArgs参数:
1. 在XAML中使用EventTrigger和InvokeCommandAction绑定事件和命令,如下所示:
```
<Button Content="Click me">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding ClickCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
```
2. 在ViewModel中定义ClickCommand,并传递sender和e参数,如下所示:
```
public ICommand ClickCommand => new DelegateCommand<object>(Click);
private void Click(object parameter)
{
var args = parameter as RoutedEventArgs;
var sender = args?.OriginalSource;
// do something with sender and args
}
```
这样就可以在ViewModel中接收sender和RoutedEventArgs参数了。注意,需要使用DelegateCommand<object>来传递参数。
阅读全文