2013-09-05 2 views
1

내가 모달 대화 상자를 표시하려고 내가 현재 쉘 창을 참조해야합니다쉘 윈도우의 현재 인스턴스에 대한 참조를 가져

public class OpenPopupWindowAction : TriggerAction<FrameworkElement> 
{ 
    protected override void Invoke(object parameter) 
    { 
     var popup = new ChildWindow(); //(ChildWindow)ServiceLocator.Current.GetInstance<IPopupDialogWindow>(); 
     popup.Owner = PlacementTarget ?? (Window)ServiceLocator.Current.GetInstance<IShell>(); 

내가 갖는 :

Cannot set Owner property to a Window that has not been shown previously. 

이것은이다 부트 스트 래퍼

의 코드
public class Bootstrapper : UnityBootstrapper 
{ 
    protected override System.Windows.DependencyObject CreateShell() 
    { 
     Container.RegisterInstance<IShell>(new Shell()); 
     return Container.Resolve<Shell>(); 

인터페이스 :

public interface IShell 
{ 
    void InitializeComponent(); 
} 

public partial class Shell : Window, PrismDashboard.IShell 

답변

1

컨테이너를 잘못 설정하고 있습니다.

이는 IShell가 요청 될 때 Shell의 특정 인스턴스를 당신을 다시 제공하는 유니티를 알려줍니다

Container.RegisterInstance<IShell>(new Shell()); 

을 그리고 이것은 Shell (안 IShell)의 인스턴스 해결을 말한다 - 그것은 행복하게 않습니다, 이전과는 다른 인스턴스를 반환 : 나중에 용기에서 IShell를 해결하면 그 결과

return Container.Resolve<Shell>(); 

, 당신은 우리를 다시되지 않은 쉘 창을 얻을 ed가 전혀없고 창 핸들이 생성되지 않았습니다.

대신이 작업을 수행 :

protected override System.Windows.DependencyObject CreateShell() 
{ 
    var shell = new Shell(); 
    Container.RegisterInstance<IShell>(shell); 
    return shell; 
} 
+0

감사합니다,이 괜찮 았는데. 이것이 어떻게 더 적절한 방법으로 행해질 수 있는지에 대한 다른 제안이 있습니까? Shell이 ​​이미 내 하위 창이있는 프로젝트에 대한 참조를 가지고있는 프로젝트로 하위 창에서 Shell을 사용할 수 없습니다. 해결 방법은 자식 및 셸 프로젝트에서 참조하는 인프라 프로젝트의 IShell입니다. – user007

+0

@ user927827 : 전적으로 컨텍스트에 따라 다릅니다. 인프라 프로젝트와의 협상은 합리적으로 들립니다. – Jon

관련 문제