我尝试了一些实现,但工作的是创建ChildView(childviewmodel)的单例实例,然后通过实例获得对属性的访问权限。它可能不漂亮,但它的工作原理。
private static ChildViewModel _instance = new ChildViewModel();
public static ChildViewModel Instance { get { return _instance; } }
#region Properties
private ChildModel _childModel= new ChildModel();
public ChildModel _childModel
{
get { return _instance._childModel; }
set
{
SetProperty(ref _instance._childModel, value);
}
}
private string _childProperty1;
public string ChildProperty1
{
get { return _childProperty1; }
set
{
SetProperty(ref _childProperty1, value);
ChildModel.ChildProperty1= _childProperty1;
}
}
在现实中 - 有很多儿童属性。我只列出了一个演示。然后我在ParentView中调用它
var _instance = ChildViewModel.Instance;
var _cm = _instance.ChildModel;
_parentModel = new ParentModel
{
Property1= ParentViewProperty1,
Property2= _cm.ChildProperty1,
};
希望能帮助别人。
我确实在想这件事。但是导航方法只有在ChildView被加载时才会被触发。我需要在填充后获取ChildView的属性值。 – theTechGrandma
我编辑了我的回复。检查这是否可以成为您的一个很好的解决方案。 – TeoVr81
谢谢!你很近。我在下面发布我的解决方案 – theTechGrandma