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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:30:53+00:00 2026-05-27T03:30:53+00:00

In my WPF application, I have a main window (Branch.xaml) which has a button

  • 0

In my WPF application, I have a main window (Branch.xaml) which has a button that will open an other window (Location.xaml). Once this Location window is open, how do I prevent another instance of this Location window from opening, when the user clicks the same button again?

Or how can I re-focus the same open window, when the user clicks the button again?

The button click code is auto-generated code when you double-click on a button in xaml.

In the “Branch.xaml.cs” file, the code for button click is as follows:

private void rbtn_Location_Click(object sender, RoutedEventArgs e) 
{ 
    Location location = new Location(); 
    location.Show(); 
} 

Location is a custom class which opens a window with 3 list boxes

Thanks, any help is appreciated.
I’m using WPF application on C# 4.0 & Visual Studio 2010.

  • 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-27T03:30:53+00:00Added an answer on May 27, 2026 at 3:30 am

    You could create a field in your main window which holds a reference to the location window if there is any, in the button click handler check if the field is null and if it is create a new window and store it in the field, if not call Activate on the window in the field. You also would have to subscribe to the Closed event of the location window to clear out the reference again when the location window is gone.

    Edit: Concrete example:

    private LocationWindow locationWindow;
    private void Button1_Click(object sender, RoutedEventArgs e)
    {
        if (locationWindow == null)
        {
            locationWindow = new LocationWindow();
            locationWindow.Closed += (s, _) => locationWindow = null;
            locationWindow.Show();
        }
        else
        {
            locationWindow.Activate();
        }
    }
    
    • 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 which has a main window composed from several custom
i'm developing an application (wpf) that have 3 windows. in the main window user
I have the following XAML below for the main window in my WPF application,
I have a WPF application with Main Window which is not a tool window
I'm using MVVM in my WPF application. I have a Window that has a
I have WPF Application where I have One main form and other user controls
I have an application in which I will have to get at another WPF
I have a wpf application using mvvm approach. The main window contains a tab
I have WPF application with one main window . In this window there are
I have a simple wpf application. In main window i have stack panel and

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.