Binding DataGrid
-
Explain why the method works so crooked add to the collection and display DataGrid.Ispolzuyu binding in XAML
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace bild
{
public partial class MainWindow : Window
{public MainWindow() { InitializeComponent(); } private void button1\_Click(object sender, RoutedEventArgs e) { ViewModel r = new ViewModel(); r.ad(); dataGrid1.ItemsSource = r.Persons; } } public class ViewModel { public ViewModel() { this.Persons = new
-
Explain why the method works so crooked add to the collection and display DataGrid.Ispolzuyu binding in XAML
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace bild
{
public partial class MainWindow : Window
{public MainWindow() { InitializeComponent(); } private void button1\_Click(object sender, RoutedEventArgs e) { ViewModel r = new ViewModel(); r.ad(); dataGrid1.ItemsSource = r.Persons; } } public class ViewModel { public ViewModel() { this.Persons = new
What is the exact problem? After a quick view, I see two things: 1) After calling the ctor of ViewModel, there will be Ivan, Stefan, Maria and Michael in the Persons collection. After calling ViewModel.Add() there will be only Maria and Michael, because you create a new collection. 2) class Person needs to implement INotifyPropertyChanged and after changing a property it has to call the PropertyChangedEvent. Hope it helps Andy