2011-08-25 5 views

답변

1

IChildWindowService라는 두 모듈에 모두 알려진 공통 인터페이스/클래스를 만들고 부트 스트 래퍼에 IChildWindowServe/ChildWindowService를 등록합니다.

//Highly simplified version 
//Can be improved by window reuse, parameter options, stronger eventing 
public class ChildWindowService : IChildWindowService 
{ 
    public ChildWindowService(IServiceLocator container) 
    { 
     _container = container; 
    } 
    public void Show<TViewModel>(TViewModel viewModel = null, Action<TViewModel, bool?> callBack = null) where TViewModel is IViewModel 
    { 
     var viewName = typeof(TViewModel).Name.Replace("Model", string.Empty); 
     // In bootstrapper register all instances of IView or register each view one by one 
     var view = _container.GetInstance<IView>(viewName); 
     viewModel = viewModel ?? _container.GetInstance<TViewModel>(); 
     view.DataContext = viewModel; 
     var window = new ChildWindow(); 
     window.Content = view; 
     var handler = (s,e) => { window.Close(); } 
     viewModel.RequestClose += handler; 
     view.Closed += (s,e) => { viewModel.RequestClose -= handler; } 
     // In silverlight all windows show as Modal, if you are using a third party you can make a decision here 
     window.Show(); 
    } 
} 

이 이벤트는 점 B 모듈 A의 뷰 모델이 이벤트를 발생시킵니다

public class OpenChildWindowWithParameters : CompositePresentationEvent<ParamEventArgs>{}

점 A에서 매개 변수를 전달하는 것, 공통 CompositePresentationEvent을 만듭니다. 모듈 B의 컨트롤러가 이벤트를 등록하고 이벤트에 반응합니다. 모듈 B의 컨트롤러는 하위 창 서비스를 종속성으로 사용합니다. 이벤트가 발생하면 Controller는 Module B에서 VM을 만들고 이벤트에서 매개 변수를 전달하며 Service를 사용하여 ChildWindow를 표시합니다.

+0

ChildWindowService 코드를 게시 할 수 있습니까? 나는 네가 다른 점을 가지고 있다고 생각해. – Prazanna

+0

@Prazanna 자식 창에 코드 추가 – Agies