急急急!!!如何更新datagrid
public class Data { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } public bool Available { get; set; } }
List<Data> source = new List<Data>(); public MainPage() { InitializeComponent(); int itemsCount = 10; for (int i = 0; i < itemsCount; i++) { source.Add(new Data() { FirstName = "First", LastName = "Last", Age = i, Available = (i % 2 == 0) }); } dg.ItemsSource = source; } private void btnAdd_Click(object sender, RoutedEventArgs e) { source.Add(new Data() { FirstName = "F", LastName = "L", Age = 1, Available = false }); dg.Resources = null; dg.ItemsSource = source; dg.Focus(); }