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

  • Home
  • SEARCH
  • 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 7792735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:16:40+00:00 2026-06-01T22:16:40+00:00

If the user closes the Application a Save-File-Message have to be shown (to be

  • 0

If the user closes the Application a Save-File-Message have to be shown (to be sure that he wants to discard the changes of edited files).

to implement this, i have a menuitem with a command-binding (without key-gesture):

private void Command_Exit(object sender, ExecutedRoutedEventArgs e)
{
    Application.Current.Shutdown();
}

the mainwindow has a closing-event. in this event i check if there unsaved files. if yes, the savedialog has to be opened (to choose, which files have to be saved):

private void Window_Closing(object sender, CancelEventArgs e)
    {
        if (sdl.Count() > 0)
        {
            SaveDialog sd = new SaveDialog();
            IEnumerable<Doc> close = sd.ShowDialog(this);
            if (close == null) 
                e.Cancel = true;
            else
                foreach (Doc document in close)
                    document.Save();
        }

    }

in this ShowDialog-Method (implemented in my SaveDialog-Class) i call

bool? ret = ShowDialog();
if (!ret.HasValue)
     return null;
if (!ret.Value)
     return null;

The problem is:

If i use the Alt+F4-Shortcut to close the Application (default-behaviour of the mainwindow) it works and i get the savedialog if there are unsaved files. but if i close the application by executing the Command_Exit-Method, the Method-Call

bool? ret = ShowDialog(); 

returns null and the dialog does not appear.

If i assign the Alt+F4 KeyGesture to the CommandBinding, the problem is switched: Executing Command_Exit works well but Alt+F4 Shortcut not.

What is the reason that the ShowDialog()-Method works not in both cases and how to fix it?

  • 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-01T22:16:41+00:00Added an answer on June 1, 2026 at 10:16 pm

    The Application.Current.Shutdown route allows you to listen for the shutdown request by handling the Exit event as detailed here:

    http://msdn.microsoft.com/en-us/library/ms597013.aspx

    It doesn’t detail how it closes windows, so I wouldn’t necessarily be convinced that the closing event handler would fire before it closes the application.

    The other very standard way to shut the application down is to close the main window (the one shown at the very beginning). This would likely be the Window.Close method, if you are in the context of the window already, just call Close(). This will then hit the closing event handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When the window closes, the user is asked to save the file that they
I have a application that allows a user to choose some parameters for a
So I have an air application that I want to save data from into
So i want to delete some files when a user closes the browser. I'm
I have implemented an Java Swing application that uses an embedded JavaDB database. The
ZipFileToCreate = c:\user\desktop\webservice\file.zip; So, when i try to save this file it creates the
Hi I have an Standalone application in which when an user logs in a
I am currently attempting to have the browser automatically prompt the user to save
In my application I am building a zip file for the User to download
I have the following code to zip all the files and then save it

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.