Wpf 简明教程

WPF - Overview

WPF 是 Windows Presentation Foundation 的缩写。它是一个用于构建 Windows 应用程序的强大框架。本教程介绍了你需要了解的用于构建 WPF 应用程序的功能,以及它如何对 Windows 应用程序带来根本性的变化。

WPF stands for Windows Presentation Foundation. It is a powerful framework for building Windows applications. This tutorial explains the features that you need to understand to build WPF applications and how it brings a fundamental change in Windows applications.

WPF 最初在 .NET Framework 3.0 版本中引入,然后在随后的 .NET Framework 版本中添加了许多其他功能。

WPF was first introduces in .NET framework 3.0 version, and then so many other features were added in the subsequent .NET framework versions.

WPF Architecture

在 WPF 之前,Microsoft 提供的其他用户界面框架(例如 MFC 和 Windows 窗体)只是 User32 和 GDI32 DLL 的包装器,但 WPF 仅极少使用 User32。因此,

Before WPF, the other user interface frameworks offered by Microsoft such as MFC and Windows forms, were just wrappers around User32 and GDI32 DLLs, but WPF makes only minimal use of User32. So,

  1. WPF is more than just a wrapper.

  2. It is a part of the .NET framework.

  3. It contains a mixture of managed and unmanaged code.

WPF 架构的主要组件如下面的图形所示。WPF 最重要的代码部分是 −

The major components of WPF architecture are as shown in the figure below. The most important code part of WPF are −

  1. Presentation Framework

  2. Presentation Core

  3. Milcore

wpf architecture

presentation frameworkpresentation core 用托管代码编写。 Milcore 是非托管代码的一部分,可以与 DirectX(负责显示和渲染)紧密集成。 CLR 通过提供内存管理、错误处理等多种功能使开发过程更具效率。

The presentation framework and the presentation core have been written in managed code. Milcore is a part of unmanaged code which allows tight integration with DirectX (responsible for display and rendering). CLR makes the development process more productive by offering many features such as memory management, error handling, etc.

WPF – Advantages

在早期 GUI 框架中,应用程序的界面外观与行为之间没有真正的区别。GUI 和行为都用同一种语言创建,例如 C# 或 VB.Net,这将要求开发人员付出更多努力来实现 UI 和与其关联的行为。

In the earlier GUI frameworks, there was no real separation between how an application looks like and how it behaved. Both GUI and behavior was created in the same language, e.g. C# or VB.Net which would require more effort from the developer to implement both UI and behavior associated with it.

在 WPF 中,UI 元素在 XAML 中设计,而行为可以用过程化语言(例如 C# 和 VB.Net)实现。因此,将行为与设计人员代码分离非常容易。

In WPF, UI elements are designed in XAML while behaviors can be implemented in procedural languages such C# and VB.Net. So it very easy to separate behavior from the designer code.

借助于 XAML,程序员可以与设计人员并行工作。GUI 与其行为之间的分离使我们能够通过使用样式和模板轻松地更改控件的外观。

With XAML, the programmers can work in parallel with the designers. The separation between a GUI and its behavior can allow us to easily change the look of a control by using styles and templates.

WPF – Features

WPF 是一个用于创建 Windows 应用程序功能强大的框架。它支持许多很棒的功能,其中一些列在下方 −

WPF is a powerful framework to create Windows application. It supports many great features, some of which have been listed below −

Feature

Description

Control inside a Control

Allows to define a control inside another control as a content.

Data binding

Mechanism to display and interact with data between UI elements and data object on user interface.

Media services

Provides an integrated system for building user interfaces with common media elements like images, audio, and video.

Templates

In WPF you can define the look of an element directly with a Template

Animations

Building interactivity and movement on user Interface

Alternative input

Supports multi-touch input on Windows 7 and above.

Direct3D

Allows to display more complex graphics and custom themes