使用 Multiple SelectionMode 执行基于 ListView 选择的命令
Execute command based on ListView selection with Multiple SelectionMode
如何使用Listview 的Multiple SelectionMode 处理命令执行?
ListView ItemsSource 绑定到 ObservableCollection (EF table),我已将选择限制设置为 2:
<ListView ItemsSource="{Binding EmployeeViewM.MainActivity}"
SelectionMode="Multiple"
IsSynchronizedWithCurrentItem="True"
HorizontalAlignment="Right"
BorderBrush="{x:Null}"
Background="{x:Null}"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.IsContainerVirtualizable="True"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
VirtualizingPanel.ScrollUnit="Item"
VirtualizingPanel.VirtualizationMode="Standard">
<I:Interaction.Behaviors>
<limit:LimitSelectionBehavior Limit="2"/>
</I:Interaction.Behaviors>
我想根据所选项目的数量执行命令 (RelayCommand)。类似于:
If SelectItems.Count = 1 Then
'Get first item selected
'Save to the database to table 1
'Start Timer_01
ElseIf SelectItems.Count = 2 Then
'Get last selected item
'Save to the database to table 2
'Start Timer_02
End If
这里如何处理多选?
感谢您的任何建议
获取列表视图的选择更改事件并遍历列表以找出选择了哪些项目。检查下面的示例代码!
public void Selection_Changed(object sender, EventArguments arg)
{
List<DataClass> selectedItems = new List<DataClass>();
foreach(DataClass item in LISTVIEWNAME.SelectedItems)
{
selectedItems.Add(item);
}
}
现在 selectedItems 将在列表视图中包含选定列表项的列表。希望你明白了!
如何使用Listview 的Multiple SelectionMode 处理命令执行? ListView ItemsSource 绑定到 ObservableCollection (EF table),我已将选择限制设置为 2:
<ListView ItemsSource="{Binding EmployeeViewM.MainActivity}"
SelectionMode="Multiple"
IsSynchronizedWithCurrentItem="True"
HorizontalAlignment="Right"
BorderBrush="{x:Null}"
Background="{x:Null}"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.IsContainerVirtualizable="True"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
VirtualizingPanel.ScrollUnit="Item"
VirtualizingPanel.VirtualizationMode="Standard">
<I:Interaction.Behaviors>
<limit:LimitSelectionBehavior Limit="2"/>
</I:Interaction.Behaviors>
我想根据所选项目的数量执行命令 (RelayCommand)。类似于:
If SelectItems.Count = 1 Then
'Get first item selected
'Save to the database to table 1
'Start Timer_01
ElseIf SelectItems.Count = 2 Then
'Get last selected item
'Save to the database to table 2
'Start Timer_02
End If
这里如何处理多选? 感谢您的任何建议
获取列表视图的选择更改事件并遍历列表以找出选择了哪些项目。检查下面的示例代码!
public void Selection_Changed(object sender, EventArguments arg)
{
List<DataClass> selectedItems = new List<DataClass>();
foreach(DataClass item in LISTVIEWNAME.SelectedItems)
{
selectedItems.Add(item);
}
}
现在 selectedItems 将在列表视图中包含选定列表项的列表。希望你明白了!