如何使用 MVVM 处理 WPF 列表框选择更改事件 [英] how to handle WPF listbox selectionchanged event using MVVM

查看:27
本文介绍了如何使用 MVVM 处理 WPF 列表框选择更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MVVM 在 WPF 中执行列表框更改事件.请让我知道如何执行此 selectionchanged 事件.

I am trying to perform listbox changed event in WPF using MVVM. Please let me know how to do this selectionchanged event.

推荐答案

您可以使用

  1. 在您的项目中添加对 System.Windows.Interactivity 的引用
  2. 在 XAML 中添加 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"

然后

<ListBox>
  <i:Interaction.Triggers>
    <i:EventTrigger EventName="SelectionChanged">
      <i:InvokeCommandAction Command="{Binding YourCommand}"
                             CommandParameter="{Binding YourCommandParameter}" />
    </i:EventTrigger>
  </i:Interaction.Triggers>
</ListBox>

这篇关于如何使用 MVVM 处理 WPF 列表框选择更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆