
AI
xaml<Window x:Class="MultipleSelectionExample.MAInWindow"</p> XMLns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" XMLns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Multiple Selection Example" Height="450" Width="800"> <Grid> <DataGrid x:Name="dataGrid" SelectionMode="Multiple"> <!-- DataGrid 的列定义 --> </DataGrid> </Grid></Window>
csharpusing System.Collections.Generic;using System.Windows;namespace MultipleSelectionExample{ public partial class MAInWindow : Window { public MAInWindow() { InitializeComponent(); // 添加示例数据 List<Person> people = new List<Person> { new Person { Name = "John", Age = 25 }, new Person { Name = "Emily", Age = 30 }, new Person { Name = "Michael", Age = 35 } }; dataGrid.ItemsSource = people; } } public class Person { public string Name { get; set; } public int Age { get; set; } }}在上述示例代码中,我们创建了一个名为 "dataGrid" 的 DataGrid 控件,并将其 SelectionMode 属性设置为 Multiple。然后,我们添加了一些示例数据,并将其绑定到 DataGrid 的 ItemsSource 属性上。这样,用户就可以直接进行多项选择,而无需按住 CTRL 或 Shift 键。通过简单地修改 DataGrid 的 SelectionMode 属性,我们可以实现无需按住 CTRL 或 Shift 键进行多项选择的功能。这在某些情况下可以提高用户的使用体验,并简化用户的操作。希望本文对你在 WPF DataGrid 中实现多项选择有所帮助。以上就是本文关于 WPF DataGrid 无需 CTRL 或 Shift 进行多项选择的介绍和示例代码。希望对你的学习和开发有所帮助!Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号