In WPF we can work with child window as dialog box. This article will provide you an explanation that how could we work with child window and dialog box in WPF
Let us assume there is a requirement,
- On click event of button, a new child window should open.
- While child window is open, the parent window should be inactive.
So start with
Step 1
Create a WPF application. And drag and drop a Button on the MainPage.
<grid>
<button content="Open New Window" x:name="BtnNewWindow" height="100" width="Auto">
</grid>
Step 2
Right click on the WPF project and new item and select a WPF Window from WPF tab. Rename window to ChildWindow.xaml

Step 3
Now on the click event of button child window will get open.
BtnNewWindow.Click += newRoutedEventHandler(delegate(object sender, RoutedEventArgs e)
{
ChildWindowchldWindow = newChildWindow();
MessageBox.Show(chldWindow.Getmessage());
chldWindow.ShowDialog();
});
On the button click event
- An instance of Child window is being created
- Then ShowDialog() method is being called to open the child window .
MainPage.Xaml.cs
using System;
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Data;
usingSystem.Windows.Documents;
usingSystem.Windows.Input;
usingSystem.Windows.Media;
usingSystem.Windows.Media.Imaging;
usingSystem.Windows.Navigation;
usingSystem.Windows.Shapes;
namespace WpfApplication2
{
///
/// Interaction logic for MainWindow.xaml
///
publicpartialclassMainWindow : Window
{
publicMainWindow()
{
InitializeComponent();
BtnNewWindow.Click += newRoutedEventHandler(delegate(object sender, RoutedEventArgs e)
{
ChildWindowchldWindow = newChildWindow();
MessageBox.Show(chldWindow.Getmessage());
chldWindow.ShowDialog();
});
}
}
}
So on running on the click of button new child window being open.
