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.