本文介绍了从viewmodel fils MVVM WPF刷新datagrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有MainWindow和Window Add,ViewModel和ViewModelADD..l'添加新客户在数据库中是正确的,但DataGrid的刷新没有!当我完成l'时,Window ADD不会关闭! ViewModel: ViewModelADD: 如何修复它? 添加新的Customer ..并刷新DataGrid,以及客户添加时...窗户添加关闭 谢谢, 我尝试过: < pre> private static ViewModel1 instance = new ViewModel1(); public static ViewModel1 Instance { get { return 实例; private void add ( object obj) { add addView = new 添加(); addView.DataContext = new ViewModelADD(loadDataBinding); addView.Show(); } private ObservableCollection< Custmor> _loadDataBinding; public ObservableCollection< Custmor> loadDataBinding { get { return _loadDataBinding ; } set { _loadDataBinding = value ; OnPropertyChanged( loadDataBinding); } } < pre> public ViewModelADD(ObservableCollection< Custmor> loadDataBinding) { CustomerToAddObject = new Custmor (); addCustomer1 = new RelayCommand(ADDFunction); } 私人 ICommand addCustomer1; public ICommand AddCustomer1 { get { return addCustomer1; } } 私有 void ADDFunction( object obj) { 使用(Test1Entities context = new Test1Entities()) { context.Custmor.Add(customerToAddObject); context.SaveChanges(); MessageBox.Show( 客户aétéajoutéavecsuccès!); } ViewModel1.Instance.loadDataBinding.Add(customerToAddObject); 解决方案 Hi,I have MainWindow and Window Add , ViewModel and ViewModelADD..l'addition of new Customer is correct in database, but the refresh of DataGrid no ! and when i finish l'addition , the Window ADD doesn't close !ViewModel:ViewModelADD:How can I fix it?to add new Customer..and refresh the DataGrid, and when the Customer added..the Window ADD closeThanks,What I have tried:<pre>private static ViewModel1 instance = new ViewModel1(); public static ViewModel1 Instance { get { return instance; } } private void add(object obj) {Add addView = new Add(); addView.DataContext = new ViewModelADD(loadDataBinding); addView.Show();} private ObservableCollection<Custmor> _loadDataBinding; public ObservableCollection<Custmor> loadDataBinding { get { return _loadDataBinding; } set { _loadDataBinding = value; OnPropertyChanged("loadDataBinding"); } }<pre> public ViewModelADD(ObservableCollection<Custmor> loadDataBinding) { CustomerToAddObject = new Custmor(); addCustomer1 = new RelayCommand(ADDFunction); } private ICommand addCustomer1; public ICommand AddCustomer1 { get { return addCustomer1; } } private void ADDFunction(object obj) { using (Test1Entities context = new Test1Entities()) { context.Custmor.Add(customerToAddObject); context.SaveChanges(); MessageBox.Show("Customer a été ajouté avec succès!"); } ViewModel1.Instance.loadDataBinding.Add(customerToAddObject); 解决方案 这篇关于从viewmodel fils MVVM WPF刷新datagrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-13 05:39