In WPF/PRISM when you create the shell it will be assigned toApp.Current.MainWindow
. However in a WPF in Browser (XBAP) the line:
App.Current.MainWindow = (Window)Shell;
fails with the error message:
Unable to cast object of type 'XBAPClient.Page1' to type 'System.Windows.Window'.
protected override DependencyObject CreateShell()
{
return this.Container.GetExportedValue<Page1>();
}
protected override void InitializeShell()
{
base.InitializeShell();
App.Current.MainWindow = (Window)Shell;
App.Current.MainWindow.Show();
}
How can I load the shell?
In XBAP Application.Current.MainWindow
is MS.Internal.AppModel.RootBrowserWindow
.
You should only assign your page to window content like this:
...
protected override void InitializeShell()
{
base.InitializeShell();
Application.Current.MainWindow.Content = Shell;
}
...