Observable Collection Benachrichtigen, wenn die Eigenschaft geändert in MVVM

Ich versuche mich zu binden beobachtbaren Sammlung DataGrid, ich will Benachrichtigen, wenn jede Zeile bearbeitet wird, in datagrid.
Mein code funktioniert gut für notifing wenn Datensatz Hinzugefügt oder entfernt, aber nicht notifing wenn Datensatz bearbeitet wird.
Bitte lassen Sie mich wissen, ob dies die richtige Art und Weise der Bindung mit observable-collection in MVVM und ob ich das bin, fehlt etwas. Vielen Dank im Voraus.

public class studentViewModel : INotifyPropertyChanged
{
    #region constructor

    public studentViewModel()
    {
        _student = new studentModel();
        myCollection = new ObservableCollection<studentModel>();
        myCollection.Add(_student);
        myCollection.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(myCollection_CollectionChanged);

    }

    void myCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        //throw new NotImplementedException();
        System.Windows.MessageBox.Show(e.Action.ToString());
    }

    #endregion

    #region properties

    studentModel _student;
    ObservableCollection<studentModel> _myCollection;

    public ObservableCollection<studentModel> myCollection
    {
        get { return _myCollection; }
        set
        {
            if (_myCollection != value)
            {
                _myCollection = value;
                raisePropertyChange("myCollection");
            }
        }
    }

    public int rollNo
    {
        get { return _student.rollNo; }
        set
        {
            if (value != _student.rollNo)
            {
                _student.rollNo = value;
                raisePropertyChange("rollNo");
            }
        }
    }

    public string firstName
    {
        get { return _student.firstName; }
        set
        {
            if (value != _student.firstName)
            {
                _student.firstName = value;
                raisePropertyChange("firstName");
            }
        }
    }

    public string lastName
    {
        get { return _student.lastName; }
        set
        {
            if (value != _student.lastName)
            {
                _student.lastName = value;
                raisePropertyChange("lastName");
            }
        }
    }

    #endregion

    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;


    public void raisePropertyChange(string propertyName)
    {
        if (PropertyChanged != null)
        {
           PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
        }
    }

    #endregion
}

public class studentModel
{
    public int rollNo { get; set; }
    public string firstName { get; set; }
    public string lastName { get; set; }
}

Und xaml ist

<Window.Resources>
    <local:studentViewModel x:Key="StudentsDetails" />
</Window.Resources>
<Grid DataContext="{StaticResource StudentsDetails}">
    <DataGrid ItemsSource="{Binding Path=myCollection, Source={StaticResource StudentsDetails}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
              Name="studentsGrid" CanUserAddRows="True" AutoGenerateColumns="True">

    </DataGrid>
</Grid>
Schreibe einen Kommentar