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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:52:42+00:00 2026-05-28T16:52:42+00:00

In my application (WPF) i have this window: public partial class Window1 : Window

  • 0

In my application (WPF) i have this window:

public partial class Window1 : Window and in the Xaml x:Class="WpfApplication1.Window1"

Now, when i switch to and from the main to window 1 and back, i us the Visibility.Hidden and Visibility.Visible to hide them and make them show again to the user.

What i try to do now, is make a test button in the main window, that says: Close Window1.
This window is hidden, but i really want to close it in the background.
at first i though to just use the Window.Close(); but that does not seem to do the trick.

So, how should i do this in a correct way ?
Thank you very much in advance.

EDIT 1 – making question more clear

To open the window1 in my Main window, i use this part

Window1 W1 = null; // Initialise Field.
  public void CalcTabel_Click(object sender, RoutedEventArgs e)
   {
    if (W1 == null)
    {
     W1 = new Window1();
     W1.Hoofdmenu = this;
     W1.checkLang();
     W1.Show();
    }
   else
    {
     W1.checkLang();
     W1.Visibility = Visibility.Visible;
    }
   this.Visibility = Visibility.Hidden;
   }

On window 1 there is a Back button, that has this snip-it of code in it (Where “Hoofdmenu” us the main window):

Hoofdmenu.updateStatistics();
Hoofdmenu.Visibility = Visibility.Visible;
this.Visibility = Visibility.Hidden;

But again, this time when standing in the main window (so window 1 is hidden) i want to close down that window 1. but using W1.Close() does not seem to work. So i am looking for a way to Close that window 1, not change its visibility.

EDIT 2 – Solution

So using W1.Close(); did not work, although a small change this.W1.Close(); did work in fact 🙂

  • 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-28T16:52:43+00:00Added an answer on May 28, 2026 at 4:52 pm

    You can create object of Form2 in window and intialize its visiblity to false.

    On click of button you can simpliy say

    public partial class MainWindow : Window
      {
        private Window1 window2;
    
        public MainWindow()
        {
          InitializeComponent();
          this.window2 = new Window1();
    
          this.window2.Show();
        }
    
        private void Button_Click(object sender, RoutedEventArgs e)
        {
          this.window2.Visibility = System.Windows.Visibility.Hidden;
        }
      }
    

    to make it visible again

    • 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 have a WPF application with the main Window class called MainWindow. Since I
I have a problem in a WPF application. I wrote this code: public partial
I have WPF application and a window in it. Lets have something like this
I have encountered something very strange, simple WPF application <Window x:Class=ListBoxSelection.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow
I have a WPF application like this. namespace WpfApplication1 { /// <summary> /// Interaction
I have a WPF application like this. namespace WpfApplication1 { /// <summary> /// Interaction
In my WPF application I have some drawing functionality. I have solved this using
I have a simple WPF application that uses ClickOnce to handle installing. Within this
In my WPF application, I have a treeview. This treeview is bound to a

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.