Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8631013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:09:27+00:00 2026-06-12T09:09:27+00:00

I am opening a WPF window from a tray app. I use the following

  • 0

I am opening a WPF window from a tray app. I use the following code to open the window:

        if (gui == null)
        {
            gui = new App();
            gui.MainWindow = new mainWindow();
            gui.InitializeComponent();
            IsUIOpen = true;
        }
        else if (!IsUIOpen)
        {
            gui.InitializeComponent();
            gui.MainWindow.Show();
            gui.MainWindow = new mainWindow();
            IsUIOpen = true;
        }

I need to run the UI from the App level because it uses a Resource Dictionary. The problem is, I need to run code when the window is closed by the user, but none of the event handlers seem to be notifying me.

I have tried the following:

gui.Exit += new System.Windows.ExitEventHandler(settings_FormClosed);
gui.MainWindow.Closed += new EventHandler(settings_FormClosed);

I have also tried gui.Deactivated, gui.SessionEnding, gui.MainWindow.Closing, gui.MainWindow.Deactivated, and probably some others.

When the user closes the window, this code is called from Shell.xaml:

    private void Cancel_Click(object sender, RoutedEventArgs e)
    {
        presenter.Close();
        this.Close();
    }

I realize App is static, so it will never close, but one of these event handlers should hook me up to a closing event.

In case it is useful, flow is as follows: TrayApp.cs -> App.xaml -> Shell.xaml

Any suggestions would be appreciated. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:09:28+00:00Added an answer on June 12, 2026 at 9:09 am

    Josh was able to give the correct solution. You can see his answer here.

    Basically, I needed to start the WPF as a separate process, and then use the MyProcess.WaitForEnd() call. I added this to a thread so it wouldn’t block the Tray. The code is as follows:

    Process myProcess = new Process();
    myProcess.StartInfo.UseShellExecute = false;
    myProcess.StartInfo.FileName = "C:\\mysettingsapp\\mysettingsapp.exe"; // replace with path to your settings app
    myProcess.StartInfo.CreateNoWindow = false;
    myProcess.Start();
    // the process is started, now wait for it to finish
    myProcess.WaitForExit();  // use WaitForExit(int) to establish a timeout
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When opening a new tkinter window, I only want the user to be able
In WPF I have one window opening a second window that allows some data
I'm new to using WPF. I have the following program I want to create:
How would I go about opening a winform from a wpf application? This needs
I'm new to WPF so this is probably a pretty easy problem. I open
I have WPF application. After testing my app on Windows7 and realized that opening
A WPF form that I launch from a WinForms window showed up with all
I'd like to have a WPF window open in the top right part of
Opening an application( probably an .exe file) as an administrator in headless mode from
i am opening jQuery Dialog through the below code.The problem here is when i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.