Wpf DataGrid Add new row

前端 未结 2 838
一生所求
一生所求 2020-12-08 14:06

I have managed to get DataGrid to show new row for adding new item. Problem i face now is i want data in the rest of wpf DataGrid to be read only a

2条回答
  •  甜味超标
    2020-12-08 14:55

    Try this MSDN blog

    Also, try the following example:

    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; }
    }
    

提交回复
热议问题