我想,以保存用户控件的窗口从用户控制视图模型的引用。 我怎样才能做到这一点?
如果我能得到从视图模型视图的参考,然后我可以使用:
Window parentWindow = Window.GetWindow(userControlReference);
所以我的问题是:
- 什么是得到用户控制视图模型,以保存用户控件的窗口中参考的最佳方式?
- 如果我想用上面的代码,是什么让一个引用从视图模型在卡利微观上的最佳方式?
我想,以保存用户控件的窗口从用户控制视图模型的引用。 我怎样才能做到这一点?
如果我能得到从视图模型视图的参考,然后我可以使用:
Window parentWindow = Window.GetWindow(userControlReference);
所以我的问题是:
一个ViewModel一般会继承IViewAware
假定它是一个IScreen
实施
您可以只投一个屏幕IViewAware
和使用GetView()
方法来获得视图的参考。 我想你可以实现IViewAware
在自己的ViewModels和卡利将自动调高ViewAttached
事件,这样你可以保持到视图的引用,但我可能会看看文档
底线:检查出IViewAware接口
编辑:
从文档...
IViewAware – Implemented by classes which need to be made aware of the view that they are bound to. It has an AttachView method which is called by the framework when it binds the view to the instance. It has a GetView method which the framework calls before creating a view for the instance. This enables caching of complex views or even complex view resolution logic. Finally, it has an event which should be raised when a view is attached to the instance called ViewAttached.