Home All Groups Group Topic Archive Search About

Load XAML in "Sub Main" in (WPF)?

Author
12 Dec 2006 3:15 PM
Horst Klein
I try to load a xaml on this way the XAML-Window is shown.
But if I close the Window the process does not stops!

What's wrong?

<Application x:Class="App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="AppStartUp"
ShutdownMode="OnMainWindowClose"
/>

Private Sub AppStartup(ByVal sender As Object, ByVal e As StartupEventArgs)
  Try
    ParseCommandLineArgs(e)
    ExecuteCommandLineArgs()
  Catch ex As Exception
    MessageBox.Show(ex.ToString)
  End Try
End Sub

Private Sub ExecuteCommandLineArgs()
  Dim mainWindow As String =
App.CommandLineArgs.Item("/mainwindow").ToString
  Dim xamlStream As FileStream = New FileStream("C:\WPF Test\" + mainWindow
+ ".xaml", FileMode.Open)
  Dim genericControl As ContentControl = XamlReader.Load(xamlStream)

  Me.ShutdownMode = System.Windows.ShutdownMode.OnMainWindowClose
  Me.MainWindow = DirectCast(genericControl, Window)
  Me.MainWindow.ShowDialog()
  Me.Shutdown()

End Sub

Author
20 Dec 2006 12:22 PM
clayb
Hi Horst,

I think this may be a framework glitch. I see the same invalid behavior
using the code below. I did notice that if I set the property to be
OnLastWindowClose, the application does shutdown.

Regards,

Clay Burch

using System;
using System.Windows;
using System.Windows.Input;

namespace test
{
    class SayHello
    {
        [STAThread]
        public static void Main()
        {
            Window win = new Window();
            win.Title = "Say Hello One";
            win.Show();

            Window win1 = new Window();
            win1.Title = "Say Hello Two";
            win1.Show();

            Application app = new Application();
            app.ShutdownMode =
ShutdownMode.OnMainWindowClose;//.OnLastWindowClose;
            app.Run();
        }
    }
}

AddThis Social Bookmark Button