0

Below is my solution tree, where you can see, that App.xaml is in G_Hoover.Init project, and BrowserView.xaml window is in G_Hoover.Views project.

solution tree

I am trying to figure out how to define StartupUri in App.xaml, that BrowserView.xaml will be a startup window.

Only approach I found is here, but when I type in App.xaml:

StartupUri="C:/Users/asus/Desktop/IT/Programowanie/Projekty/G_Hoover/G_Hoover.Views/BrowserView.xaml"

I receive an exception:

XamlObjectWriterException: Specified class name 'G_Hoover.Views.BrowserView' doesn't match actual root instance type 'System.Windows.Window'. Remove the Class directive or provide an instance via XamlObjectWriterSettings.RootObjectInstance.

When I type:

StartupUri="pack://application:,,,/G_Hoover;G_Hoover.Views/BrowserView.xaml">

I receive exception:

System.IO.IOException: 'Cannot locate resource 'g_hoover;g_hoover.views/browserview.xaml'.'

And the same results I have when I type it in App.xaml.cs basing on this approach:

public partial class App : Application

{
    protected override void OnStartup(StartupEventArgs e)
    {
        StartupUri = new Uri("pack://application:,,,/" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ";G_Hoover.Views/BrowserView.xaml", UriKind.RelativeOrAbsolute);
        //or this: StartupUri = new Uri("pack://application:,,,/G_Hoover;G_Hoover.Views/BrowserView.xaml", UriKind.RelativeOrAbsolute);
        //or this: StartupUri = new Uri("C:/Users/asus/Desktop/IT/Programowanie/Projekty/G_Hoover/G_Hoover.Views/BrowserView.xaml");
    }
}

Please note that G_Hoover.Init has reference to G_Hoover.Views. What am I doing wrong?

1 Answers1

1

You can remove StartupUri from App.xaml and manage app startup in App.xaml.cs.

For example:

public partial class App : Application
{

    protected override void OnStartup(StartupEventArgs e)
    {
        var startupView = new G_Hoover.Views.BrowserView.xaml();
        startupView.ShowDialog();

        base.OnStartup(e);
    }
}
AmRo
  • 833
  • 1
  • 8
  • 19
  • Actually it worked and was more simple than I expected to be. Thank you. –  Aug 09 '19 at 05:29