.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> WPF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Craete Child Window in WPF

Posted By:Dhananjay Kumar       Posted Date: September 08, 2010    Points: 25    Category: WPF    URL: http://www.dotnetspark.com  

Create Child Window in WPF. In this article you will learn how to use Child Window in WPF.
 

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.

child1.gif

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

child2.gif

Step 3

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

child3.gif

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
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
    public MainWindow()
    {
        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.

child4.gif

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend