How to create Child Window in WPF

No.of Views8292
Bookmarked0 times
Downloads 
Votes0
By  Dhananjay Kumar   On  05 Sep 2010 10:09:05
Tag : WPF , Applications
In this article, i will demonstrate how to create child Window in WPF
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Let us assume there is a requirement,

1.    On click event of button, a new child window should open.
2.    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 

Image Loading

Step 2

Right click on the WPF project and new item and select a WPF Window from WPF tab.  Rename window to ChildWindow.xaml 

Image Loading

Step 3

Now on the click event of button child window will get open. 

Image Loading

On the button click event

1.    An instance of Child window is being created
2.    Then ShowDialog() method is being called to open the child window .

MainPage.Xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication2
{/// <summary>/// Interaction logic for MainWindow.xaml/// </summary>public partial class MainWindow : Window
    {public MainWindow()
        {
            InitializeComponent();
            BtnNewWindow.Click += new RoutedEventHandler(delegate(object sender, RoutedEventArgs e)
                                                          {
                                                              ChildWindow chldWindow = new ChildWindow();
                                                              MessageBox.Show(chldWindow.Getmessage());
                                                              chldWindow.ShowDialog();
                                                          });
          
                   
                          
        }

        
    }
}

 So on running on the click of button new child window being open. 

Image Loading

that's all, hope this help.

 
Sign Up to vote for this article
 
About Author
 
Dhananjay Kumar
Occupation-Software Engineer
Company-Infosys Technolgies,Pune
Member Type-Gold
Location-India
Joined date-20 Jul 2009
Home Page-http://dhananjaykumar.net/
Blog Page-http://dhananjaykumar.net/
Dhananjay Kumar is Microsoft MVP on connected system. He blogs at http://dhananjaykumar.net/ . You can follow him http://twitter.com/debugmode_/ and reach him at dhananjay.25july@gmail.com
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top