我正在尝试显示模态对话框,我需要引用当前的Shell窗口:
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.
这是Bootstrapper的代码
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
答案 0 :(得分:1)
您正在设置容器错误。
这告诉Unity在请求Shell
时回复IShell
的具体实例:
Container.RegisterInstance<IShell>(new Shell());
这告诉它解决一个Shell
(不是IShell
)的实例 - 它很乐意做,返回一个与以前不同的实例:
return Container.Resolve<Shell>();
因此,当您稍后从容器中解析IShell
时,您将返回一个尚未使用的shell窗口,并且尚未创建其窗口句柄。
请改为:
protected override System.Windows.DependencyObject CreateShell()
{
var shell = new Shell();
Container.RegisterInstance<IShell>(shell);
return shell;
}