我有一个在整个应用程序中使用的对象,它可以被一些 ViewModel 修改;我应该如何注册对象AppBootstrapper
?
考虑以下代码:
应用引导程序
protected override void Configure()
{
this.container = new PhoneContainer(RootFrame);
this.container.RegisterPhoneServices();
var myObject = this.CreateDefaultObject();
this.container.Instance(myObject);
// ... etc.
}
private MyObject CreateDefaultObject()
{
// blah blah blah
return new MyObject {
Status = "New"
};
}
视图模型1
public ViewModel1(MyObject myObject, INavigationService navigationService)
{
this.myObject = myObject;
this.navigationService = navigationService;
}
public string Status
{
get { return this.myObject.Status; }
}
视图模型2
public ViewModel2(MyObject myObject, INavigationService navigationService)
{
this.myObject = myObject;
this.navigationService = navigationService;
}
public ModifyIt()
{
this.myObject = new MyObject {
Status = "Modified"
};
this.navigationService.GoBack();
}
场景是:
- 应用程序运行并导航到 View1,它将在
TextBlock
- 用户导航到 View2 并执行操作
ModifyIt
(例如Button
单击) - 应用程序导航回 View1,这次显示的值应该是“Modified”
感谢任何帮助。