I have a WPF application with a main window and a second window that can be opened from a button in the main window. I want the main window to be disabled while the second window is open as an "About" window in Visual Studio.
2 Answers
Try this ShowDialog
method instead of Show
to open the second window as a dialog.
You have a WPF project already with a window. This app should work.
Right click on project and Add new Window. You name it Window1.xaml
You would now notice Window1.xaml and Window1.xaml.cs added to your project. (the class name for the window would be Window1 which is in the .xaml.cs file and it derives from Window; also a partial class)
Open the XAML file for the Window1 (Window1.xaml) and add your controls. Treat it like any other window and write code.
Now in your main window (the first one) you add a Button which when clicked should show the newly created window.
For that inside the Click handler, ....
var newWindow = new Window1();
newWindow.ShowDialog();
This Window1
should be the design for your About page. Invoking it with ShowDialog();
disables the other windows and the only active window will be your about page.
There is a difference between the ShowDialog()
and Show()
methods. ShowDialog()
makes the child window active and remain active until it is closed; however, the Show()
method opens a new window and treats it as a separate entity. In this case, on every click, a new window gets launched.
E.g.
Window1 childWin= new Window1();
childWin.ShowDialog();
OR
childWin.Show();