Application MainWindow in WPF

MainWindow property gets or sets the main window of the application. The code snippet in Listing 4 gets the MainWindow.

Application curApp = Application.Current;
Window mainWnd = curApp.MainWindow;

Listing 4

The code snippet in Listing 5 sets MainWindow property in XAML.

<Application x:Class="WPFSample.App"






        <NavigationWindow Source="Window1.xaml" Visibility="Visible">


Listing 5


Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now