WPF Tutorial One: Basics

Source: Internet
Author: User

I. Introduction to WPF
WPF:WPF, the Windows Presentation Foundation, translates to the Chinese "Windows Rendering Fundamentals", a Microsoft-launched Windows Vista-based user interface framework that is part of the. NET Framework 3.0. It provides a unified programming model, language and framework that truly separates the interface designer from the developer, and it provides a new interactive user graphical interface for multimedia.

Ii. features of WPF
1. Unified programming Model
WPF provides a programming model that unifies common controls, voice, video, and document-based technologies, and these media types work together to reduce our learning costs.
2, independent of resolution
WPF is based on vector graphics, so it produces a graphical interface that supports display devices of various resolutions, rather than generating aliasing on high-resolution real-world devices like WinForm.
3. Hardware Acceleration Technology
WPF is created based on Direct3D. In WPF applications, whether 2D or 3D graphics or text content is converted to 3D triangles, materials, and other Direct3D objects, and is rendered by the hardware, it makes better use of the system's image processing unit GPU to derive benefits from hardware acceleration.
4. Declarative programming
WPF introduces a new XAML language (extensible Application Markup Language) to develop the interface. The use of XAML language to develop the interface and background logic is well separated, reducing the coupling between the front and rear development, so that user interface designers and program developers can better cooperate, reduce maintenance and update costs.
5. Easy to deploy
In addition to using traditional Windows Installer and ClickOnce to publish our desktop applications, WPF can publish our applications as a browser-based application with a slight change.

Iii. commonly used auxiliary development tools
Kaxaml: is a lightweight XAML editor that lets you quickly view XAML code and the UI interface that XAML presents.
Microsoft Expression Blend: Short (blend) It is a must-have tool for the WPF UI interface designer, which allows us to design a very beautiful UI interface, as well as the interface style, templates, animations and other resources.

kaxaml:http://www.kaxaml.com/
blend:https://msdn.microsoft.com/zh-cn/(search for blend)

Iv. Development Fundamentals

1. Create a new WPF application

Select New Project, File, menu, select the WPF application in the New Project dialog box, modify the name Wpfdemo, and then click the OK button, as shown in:

2, the resulting document structure diagram is as follows:

3. The "StartupUri" property in App.xaml can specify the startup form when the project runs. As in "startupuri=" MainWindow.xaml "", we can also define the system resources we need and introduce the assembly, etc.

As shown in the following:

V. XAML language

XAML language: A new Extensible Application Markup Language, created by Microsoft to build the application user interface, provides an easy-to-expand and positional syntax for defining and separating program logic from the user interface.
Characteristics:
Defining an interface element for an application
Display declarations for WPF resources (styles, templates, animations, and so on)
Extensibility (custom UI controls)
Focus on the design and implementation of the interface

Vi. XAML namespaces and namespaces mapped to assemblies

1. xaml Namespaces

The development language encapsulates common functionality in the form of classes, and developers encapsulate classes that meet their business needs, if they are organized in an orderly fashion, based on their business needs. On the one hand, it is convenient for the developers to call accurately; On the other hand, the compiler can effectively identify the class with the same naming, introduced the namespace, simply, through a similar tree structure to organize the various classes, is a more efficient way to arrange the class name.
And, as in the case of. NET other languages, it is also useful to organize the relevant element classes within XAML through namespaces, where the namespaces are not one by one corresponding to the namespaces in. NET, but one-to-many, and a "url," where URLs are followed by the XAML parser standard naming conventions , not the real URL (it won't open in IE).

xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml" corresponds to some CLR namespaces related to XAML syntax and compilation, such as
<style x:key= "Buttonmouseover" targettype= "{x:type button}" >

The difference between xmlns and xmlns:x here is that X is used as an alias, when applied, in the prefix form, and xmlns as the default namespace, not the element identified by the prefix, from that namespace.

Syntax for XAML namespaces:
xmlns[: Optional mapping prefix]= "namespace description"
Note: xmlns without an optional mapping prefix is the default namespace for WPF, and a XAML file can have only one default namespace
A complete XAML file, you must have two namespaces.

2. Custom class or assembly mapping syntax
xmlns[: Required mapping prefix]= "clr-namespace:[namespace];assembly=[assembly name]"

Create a new "" Project under the same solution named "Wpfusercontrol", and in the project's properties, modify the default namespace to: Mycontrol.wpfusercontrol, add two TextBlock and two textbox:

In the first project, refer to the new user control, note: First add a reference to the new user Control Library.

3. Syntax mapped to the current assembly
xmlns[: Required mapping prefix]= "clr-namespace:[namespace]"

Create a new user control below the current project, add two TextBlock and two textbox, as shown in:

To invoke the new user control inside the MainWindow.xaml, you need to reference the namespace:

WPF Tutorial One: Basics

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.