2

ユーザーコントロールビューモデルから、ユーザーコントロールを保持するウィンドウへの参照を取得したいと思います。これどうやってするの?

ビューモデルからビューへの参照を取得できる場合は、次を使用できます。

Window parentWindow = Window.GetWindow(userControlReference); 

だから私の質問は:

  1. ユーザーコントロールビューモデルからユーザーコントロールを保持するウィンドウへの参照を取得するための最良の方法は何ですか?
  2. 上記のコードを使用したい場合、Caliburn Microのビューモデルからビューへの参照を取得するための最良の方法は何ですか?
4

1 に答える 1

4

ビューモデルは通常、それが実装IViewAwareであると想定することから継承しますIScreen

Screenをキャストし、メソッドをIViewAware使用してビューへの参照を取得できます。GetView()独自のビューモデルに実装できIViewAware、Caliburnが自動的に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.

于 2012-10-16T09:06:25.860 に答える