Vs to create the simplest WPF program _c# Tutorial in imitation of the WPF template

Source: Internet
Author: User

How do you create a WPF program manually without using the VS WPF project template? Let's emulate the WPF template and create one of the simplest WPF programs.

First step: file--New--project--Empty project, create an empty project .

Step Two: add references, Presentationframework,presentationcore,windowsbase,system,system.xaml, which are the core DLLs of WPF.

Step Three: right-click on the item to add a new item, add two "XML Files", named App.xaml and MainWindow.xaml respectively. As you can see, the XAML file is actually an XML file.

Fourth Step: In the second step , add two code files, a blank C # code file, named App.xaml.cs and MainWindow.xaml.cs, respectively. As you can see, these two files automatically become the Code-behind files for the two files generated in the second step.

Step Fifth: add XAML and C # code:

App.xaml and MainWindow.xaml to delete the automatically generated XML file headers, add the following XAML markup, respectively:

<application x:class= "Wpfapp.app"
       xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
       startupuri= "MainWindow.xaml" >
  < application.resources>
     
  </Application.Resources>
</Application>
<window x:class= "Wpfapp.mainwindow"
    xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
    Title= "MainWindow" height= "width=" 525 ">
  <Grid>
    
  </Grid>
</Window>

Add code similar to the following in App.xaml.cs and MainWindow.xaml.cs, respectively:

Using System.Windows;

Namespace Wpfapp
{
  ///<summary>
  ///app.xaml Interactive logic
  ///</summary>
  Public Partial class App:application
  {
  }
}
Using System.Windows;

Namespace Wpfapp
{
  ///<summary>
  ///mainwindow.xaml Interactive logic
  ///</summary>
  Public Partial class Mainwindow:window
  {public
    MainWindow ()
    {
      InitializeComponent ();
}}}

The sixth step: if compile at this time will be an error, the hint did not find the main function entrance, this main function does not actually add itself, the system will automatically generate. Opens the App.xaml file property, changing the build Action from page to ApplicationDefinition.

Seventh Step: This should already be operational, the system default output is the console application, you can open the Project property page, the output type to the Windows application.

At this point, a simple WPF program that mimics vs's WPF project template is ok.

The above is the entire content of this article, I hope to help you learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.