美文网首页
MVVMLight PassEventArgsToCommand

MVVMLight PassEventArgsToCommand

作者: 魔人健太郎 | 来源:发表于2020-10-13 02:59 被阅读0次
<i:Interaction.Triggers>
    <i:EventTrigger EventName="PreviewMouseUp">
        <cmd:EventToCommand Command="{Binding DataContext.WordSearchCommand, 
                                              RelativeSource={RelativeSource AncestorType=UserControl} }"
                                              PassEventArgsToCommand="True" />
    </i:EventTrigger>
</i:Interaction.Triggers>

PassEventArgsToCommand 设置为True,可以把各种事件参数传递回ViewModel。诸如 DragEventArgs MouseButtonEventArgs 等。
在ViewModel通过 public RelayCommand<MouseButtonEventArgs> 接收
handle函数 可以

private void WordSearch(MouseButtonEventArgs e)
{
    var target = e.Source as TextBlock;//某一控件
}'

相关文章

网友评论

      本文标题:MVVMLight PassEventArgsToCommand

      本文链接:https://www.haomeiwen.com/subject/lpympktx.html