2

I can't get my MainWindow to show without using StartupUri. OnStartup doesn't trigger.

I removed StartupUri from App.xaml

<Application x:Class="SCon"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</Application>

added the following in the code behind

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        SCon.MainWindow.Instance.Show();
    }

MainWindow is a singleton

    private static volatile MainWindow instance = null;
    private static object lockThis = new object();
    public static MainWindow Instance
    {
        get
        {
            if (instance == null)
            {
                lock (lockThis)
                {
                    if (instance == null)
                    {
                        instance = new MainWindow();
                    }
                }
            }
            return instance;
        }
    }
Tsukasa
  • 6,342
  • 16
  • 64
  • 96
  • There has to be something that's specified as a start up window. Do you mean you want 2 windows to show up automatically when your application starts? – Rod Feb 11 '14 at 20:30
  • No it's only the MainWindow turned into a singleton. So I try to override OnStartup to create my window but it never triggers OnStartup – Tsukasa Feb 11 '14 at 20:32

2 Answers2

2

Idk what you mean or where you stuck at. I would check Build Actions of App.xaml then I would take a look to this site.

http://www.erikojebo.se/Code/Details/202

That guy explains is pretty well :)

Also your question is sort of a duplicate. Check this out: How to change StartupUri of WPF Application?

Community
  • 1
  • 1
dev hedgehog
  • 8,698
  • 3
  • 28
  • 55
1

You need to put the following line in the XAML file:

<Application x:Class="SCon"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         Startup="OnStartup">
</Application>

That's why it didn't trigger the OnStartup method.