C# 使用INotifyPropertyChange执行添加操作后未更新Datagrid
我最近学习了C# 使用INotifyPropertyChange执行添加操作后未更新Datagrid,c#,wpf,fody,C#,Wpf,Fody,我最近学习了INotifyPropertyChanged,并使用Fody在我的所有类中实现了它 在向我的应用程序添加添加选项以及Datagrid时,我注意到Datagrid在添加新数据时不会更新。 很可能我实现了INotifyPropertyChanged错误,但我相信我的实现与我遇到的每个答案都匹配。有人能告诉我为什么我的Datagrid没有更新吗? Fody和PropertyChanged都作为NuGet软件包安装 我的xaml.cs带有添加操作 EFContext db =
INotifyPropertyChanged
,并使用Fody在我的所有类中实现了它
在向我的应用程序添加添加选项以及Datagrid时,我注意到Datagrid在添加新数据时不会更新。
很可能我实现了INotifyPropertyChanged
错误,但我相信我的实现与我遇到的每个答案都匹配。有人能告诉我为什么我的Datagrid没有更新吗?
Fody和PropertyChanged都作为NuGet软件包安装
我的xaml.cs带有添加操作
EFContext db = new EFContext();
Controller cont = new Controller();
cont.Name = txt_CName.Text;
cont.ControllerVersion = 8 ;
cont.IDEName = CB_IDE.Text ;
cont.UploadDate = DateTime.Now;
cont.InstallationID = Convert.ToInt32(CB_Instal.SelectedValue.GetHashCode());
cont.Controllerxml = txt_Code.Text;
//add entity to the add method
db.Controllers.Add(cont);
db.SaveChanges();
以及以示例github为模型的数据类
db.Controllers.Add(续)
不设置控制器的任何属性,因此该类是否实现INotifyPropertyChanged无关紧要。您需要的是来自EFContext类的Controllers属性的集合更改通知。它可能被声明为ObservableCollection。
public class Controller : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public int ControllerID { get; set; }
public string Name { get; set; }
public int ControllerVersion { get; set; }
public string IDEName { get; set; }
public DateTime UploadDate { get; set; }
public string Controllerxml { get; set; }
public int InstallationID { get; set; }
public Installation Installation { get; set; }
}