WPF MVVM 获取List 多选数据
单选绑定
使用 SelectedIndex
或 SelectedItem
都可以
<ListBox x:Name="dataGrid1" SelectedIndex="{Binding SelectedIndex}" SelectedItem="{Binding SelectedItem}">
</ListBox>
多选绑定
要先添加依赖项 System.Windows.Interactivity.dll
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
<ListBox x:Name="dataGrid1">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectionChangeCommand}" CommandParameter="{Binding SelectedItems,ElementName=dataGrid1}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
转载请保留原文链接: https://zodream.cn/blog/id/247.html