2014-12-04 3 views
0

스레드 View not connecting to ViewModel using MEF을 참조하고있었습니다.

비슷한 시나리오이지만 몇 개의 애드온이 있습니다. 응용 프로그램은 여러 모듈로 구성되며 셸에서는 주 영역을 정의합니다. 각 모듈은 view (userControl)와 viewmodel을 가지며 필요에 따라 뷰가 쉘 영역에로드됩니다. 문제는 View 자체의 ViewModel을 갖는 자식 usercontrol로 구성된다는 것입니다. 그래서 뷰의 여러 인스턴스를 가질 수 있으므로 뷰에 정의 된 범위 영역에 하위 컨트롤을 삽입하기로 결정했습니다.
그러나 어떻게 든 나는 MEF를 사용하는 것을 끝내지 않을 것입니다.

다음은 의사 코드 및 앱 구조입니다.

1.Shell에는 Mainregion이 정의되어 있습니다. 요청시이 MainRegion에서 부모보기가로드됩니다.
2. FooParent에 xaml이있는 부모 뷰. 여기서 내가 영역을 정의합니다.
<ContentControl prism:RegionManager.RegionName ="FooChildRegion" />
3. FooChildUsercontrol 코드 숨김 클래스는 [내보내기] 특성으로 표시됩니다.
4. FooParentModule는 regionmanager 가져 생성자
5. 코드 모듈의 초기화 방법에
범위 영역 중첩 된보기

IRegion foochildregion = this._regionManager.Regions["FooChildRegion"]; //This blows. 
FooChildView fooChildView = new FooChildView(); 
IRegionManager allocationViewRegionManager = foochildregion .Add(fooChildView , null, true); 
foochildregion .Activate(fooChildView); 

FooChildRegion의 인스턴스를 얻기위한 첫 번째 줄이 불면 모듈이 시작시 초기화로하고있는 초기화 방법이있다 뷰는 필요에 따라로드됩니다.

내가 여기에 무엇을 놓치고 있는지 알 수 있습니까?

답변

1

나는이 문제를 해결하려고합니다. 부모에서 나는이 ContentControl 부모 컨트롤의 뒤에있는 코드에서 다음

<ContentControl x:Name="FooChildContentControl" /> 

으로 내가 regionManager의 새 인스턴스를 만들 정의

IRegionManager regionManager = ServiceLocator.Current.GetInstance<IRegionManager>(); 
RegionManager rm = new RegionManager(); 
RegionManager.SetRegionManager(this.FooChildContentControl, rm); 
RegionManager.SetRegionName(this.FooChildContentControl, "FooChildRegion"); 
rm.RegisterViewWithRegion("FooChildRegion", typeof(fooChildView)); 
아래로 자식 컨트롤로 설정