WPF Datagrid set the column values only when the row is left
- by Noam
Hello
I have a simple class. When I use it in winforms binding, whenever I change a value of a cell and leave the cell, the property immediately get changed.
Using WPF Datagrid, whenever i change a value of a cell, the property gets set only after I leave the row. That is problematic for me. What am I doing wrong?
Here is my code:
public class MyClass : IEditableObject, INotifyPropertyChanged
{
string _name, _lastName;
public string Name
{
get { return _name; }
set
{
_name = value;
_lastName = value + " xxx";
OnPropertyChanged("LastName");
MessageBox.Show("Test");
}
}
private void OnPropertyChanged(string p)
{
var x = new PropertyChangedEventArgs(p);
if (PropertyChanged != null)
PropertyChanged(this, x);
}
public string LastName { get { return _lastName; } set { _lastName = value; } }
public void BeginEdit()
{
}
public void CancelEdit()
{
}
public void EndEdit()
{
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class myBindingList : BindingList<MyClass>
{
public myBindingList()
{
AllowNew = true;
Add(new MyClass { Name = "noam" });
Add(new MyClass { Name = "yael" });
}
}