다음을 통해 공유


WPF: Creating a New Window

Prerequisites

  • Visual Studio 2013 with Update 4 or Visual Studio 2015 

Steps

Follow the below steps to create a new window in WPF

Step 1: Emtpy WPF

Create an empty WPF using Visual Studio, enter the name for the application and click on OK

Step 2: Create Button

Create a button using the following code or drag and drop a button from the ToolBox of Visual Studio 2013. 

Code:

Step 3:  New window

Solution Name(Right Click) --> Add à New Window

Step 4: Name window

Name the New window and click on OK

Step 5: Add menu

Add the Menu items that you need on this page. I have added a TextBox over here (use ToolBox or code)

Code:

TextBox="Left"="23"="119,98,0,0"="Wrap"="TextBox"="Top"="120"/>Rename the Text if you need

Now move to MainWindow.xaml and double click on the Button, enter the following code

Newwindow            p.Show();

Code for Mainwindow.xaml.cs is:

using System.Collections.Generic;
 
using System.Text;
 
using System.Windows;
 
using System.Windows.Data;
 
using System.Windows.Input;
 
using System.Windows.Media.Imaging;
 
using System.Windows.Shapes;
 
  
 
///<summary>
 
    Interaction logic for  MainWindow.xaml
 
    public class  Window
 
    {
 
        private object  sender, Newwindow            p.Show();
 
        }
 
    }
 
}

 

Now run the program: