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 3347016
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:22:19+00:00 2026-05-18T01:22:19+00:00

In WPF you get to call ShowDialog on a window exactly once. After that

  • 0

In WPF you get to call ShowDialog on a window exactly once. After that it is done for.

Seems kind of lame to me, but those are the rules. If you call ShowDialog again you get this exception:

Cannot set Visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after a Window has closed

What I want to know is: How can I take a Window (or UserControl really) and check to see if it has had ShowDialog called (so I know to new up a different one before calling ShowDialog again).

Something like this:

public void ShowListOfClients()
{
    //    |  This is the method I want to write
    //    V                                          
    RefreshViewIfNeeded(_myWindowOrUserControlThatShowsAList);

    FillWindowWithBusinessData(_myWindowOrUserControlThatShowsAList);
    _myWindowOrUserControlThatShowsAList.ShowDialog();

}

NOTE: Clearly in the above example it would be easier to just create a new WindowOrUserControlThatShowsAList every time I enter the method. But please consider the question more that the dumbed down example.

  • 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-05-18T01:22:20+00:00Added an answer on May 18, 2026 at 1:22 am

    This isn’t exclusive to ShowDialog(), Show() does it too. And no, there is no IsDisposed property to check. IsLoaded is only half a solution, it will be false for the 1st invocation as well.

    First approach is to just make a dialog that can be re-shown:

        public bool CloseAllowed { get; set; }
    
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
            if (!CloseAllowed) {
                this.Visibility = System.Windows.Visibility.Hidden;
                e.Cancel = true;
            }
        }
    

    The next one is to explicitly keep track of the health of the object reference:

        private Window1 win = new Window1();   // say
    
        private void button1_Click(object sender, RoutedEventArgs e) {
            if (win == null) {
                win = new Window1();
                win.Closing += delegate { win = null; };
            }
            win.ShowDialog();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application that's crashing once I get it onto machines that
I have a WPF window that has TopMost=true . When I call another Window
This seems like it should be a no-brainer, but I can't get a WPF
Got an application (C# WPF) that needs to call home and get updated stuff
I try to get all WPF window controls collections. In other words i try
I would like to get the XAML source of a WPF Window (MainWindow). Clicking
I try to get the following done: A WPF application where i have multiple
I have WPF window that uses a dockpanel and the menu control. I have
I'm trying to get value after window dialog is closed: public partial class MyDialogWindow:
I have a WPF C# application here, finally have solved errors. But after 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.