WPF disables the main window, and the second window is open until closed

I have a WPF application with a main window and a second window, which can be opened using the button in the main window. I want the main window to be disabled while the second window is open as the "About" window in Visual Studio.

+12
source share
1 answer

Try this ShowDialog method instead of Show to open the second window as a dialog.

  • You already have a WPF project with a window. This app should work.

  • Right-click on the project and add a new window. You call him Window1.xaml

  • Now you will notice that Window1.xaml and Window1.xaml.cs are added to the project. (the class name for the window will be Window1, which is in the .xaml.cs file, and it is derived from Window, as well as a partial class)

  • Open the XAML file for Window1 (Window1.xaml) and add controls. Treat it like any other window and write code.

  • Now in your main window (first) you add a button that when clicked should show the window you just created.

To do this, inside the Click handler, ....

 var newWindow = new Window1(); newWindow.ShowDialog(); 

This Window1 should be the design for your About page. Call using ShowDialog(); disables other windows and your page will be the only active window.

+36
source

Source: https://habr.com/ru/post/1207644/


All Articles