Wpf DataGrid添加新行
我设法让DataGrid
显示添加新项目的新行。 我现在面临的问题是我希望wpf DataGrid
的其余部分中的数据只读,并且只能编辑新行。
目前这是我的DataGrid
外观。
但由于我保持列只读,所以新行也添加为只读,这是我不想要的。
试试这个MSDN博客
另外,请尝试以下示例:
XAML:
CS:
/// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Button_Click_1(object sender, RoutedEventArgs e) { var data = new Test { Test1 = "Test1", Test2 = "Test2" }; DataGridTest.Items.Add(data); } } public class Test { public string Test1 { get; set; } public string Test2 { get; set; } }
只需使用此Style
of DataGridRow
: