Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未将属性从propertyGrid绑定到customUserControl_C#_Wpf_User Controls - Fatal编程技术网

C# 未将属性从propertyGrid绑定到customUserControl

C# 未将属性从propertyGrid绑定到customUserControl,c#,wpf,user-controls,C#,Wpf,User Controls,在我正在处理的应用程序中,有userControls和propertyGrid来显示一些属性。当加载属性并在propertyGrid中更改它们的值时,我可以看到userControl也在更新。有一个功能可以撤消更改。为此,当用户选择编辑userControl时,我创建了userControl的deepCopy并继续使用原始对象。当用户选择“撤消更改”时,我会将副本设置为原始对象: var control = temp.ViewModel.AllControls.FirstOrDefault(x

在我正在处理的应用程序中,有userControls和propertyGrid来显示一些属性。当加载属性并在propertyGrid中更改它们的值时,我可以看到userControl也在更新。有一个功能可以撤消更改。为此,当用户选择编辑userControl时,我创建了userControl的deepCopy并继续使用原始对象。当用户选择“撤消更改”时,我会将副本设置为原始对象:

var control = temp.ViewModel.AllControls.FirstOrDefault(x => x.ViewModel.IsSelected); //finds selected userControl
if (control == null) return;

var t = (ISelectableViewModel)_copySelectedObject;
control.ViewModel = t; // set old values to userControl           
SelectedObject = control.ViewModel; // load properties in propertyGrid

问题是,在单击“撤消”按钮后,我的userControl没有更新为新值(仅当我写入代码control.ViewModel.Name=t.Name等时)。我对propertyGrid也有问题。它加载正确的值,但当我更改属性时,它不会影响我的userControl。我能做些什么来解决这个问题?

好的,我已经解决了。为此,我将userControl的datacontext更改为userControl的副本。希望这对将来的人有所帮助。

您是否在
ViewModel
属性上实现了
INotifyPropertyChanged
接口?@Sheridan是的。我已经通过重置userControls datacontext修复了它。你所说的UserControl的副本是什么意思?@RohitVats我所说的UserControl的副本是我在编辑UserControl属性之前制作的UserControl的深度副本。