未将属性从propertyGrid绑定到customUserControl



在我正在开发的应用程序中,有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.名称等时)。此外,我对propertyGrid也有问题。它加载正确的值,但当我更改属性时,它不会影响我的userControl。我能做些什么来解决这个问题?

好的,我已经解决了。为此,我将userControl的数据上下文更改为userControl的副本。希望这对将来的某个人有所帮助。

最新更新