WPF step by step series-opening part

Source: Internet
Author: User

The company recently asked me to organize a complete WPF training tutorial. I just summarized the process and experience of learning WPF into notes, this is not based on what is written in the book. Generally, the books are step-by-step and easy to understand. I am here mainly based on actual practice and specificCode.

At present, the use of WPF is not long. It may take more than two years. It is much worse than many masters in the garden. I have just mastered the basic applications of WPF, but I still have a lot to do with uidesign. Because I am not very good at aesthetic things.

Recommended WPF reference books

Next, I will first sort out the WPF reference books I have studied:

1. WPF programming book (C #2010)

Book :(Mandatory)

Experience: after reading this book, you will be able to use the basic and basic controls of WPF, including the WPF programming model. Compared with the features of winform and how to get started in real projects, all have basic cognition. It also introduces the use of the control template. WPF must master the template. It includes all aspects of WPF. However, the depth remains to be explored.

2. go deep into WPF

This book (Entry required)

Experience: This is easy to understand. It is especially suitable for books that do not know about WPF and are eager to get started quickly with WPF. It is easy for Chinese to read the book. However, this book does not contain much content that combines project instances. Is a good book.

3. WPF programmer's reference: Windows Presentation Foundation with C #2010 and. Net 4

Book: (recommended)

Experience: The book is in English, and it will be difficult to read at the beginning. However, once you read the first two WPF books, it will not be so difficult again. This book introduces the features and usage of WPF in great detail, which helps people in the process of developing the WPF project and solves many basic problems.

4. WPF 4 unleashed

This book (recommended)

Experience: the content of this book is basically similar to the content of the above books, but it will be further explained in some specific WPF features, it is more suitable for those who study WPF in depth.

5. Sams Teach Yourself WPF in 24 hours

 

 

This book (recommended)

Experience: the content of this book is based on the teaching method. After twenty-four hours, it will be easier at the beginning, and the subsequent content will be relatively deeper, it is suitable for those who want to learn WPF from the beginning. After learning, they will have a basic understanding of WPF usage.

The above introduction only represents my personal opinion. Please do not make a picture.

Content contained in the WPF Series
    • Basic WPF knowledge
    • WPF Layout
    • WPF controls (including third-party controls)
    • WPF custom template
    • WPF dependency attributes and routing events
    • Mvvm programming for WPF
    • WPF development framework prism
    • WPF development framework WAF
    • WPF development framework Caliburn
Why do we choose WPF? Introduction

Windows apiwindows Presentation Foundation (WPF) is the next-generation display system used to generate Windows client applications that can bring users an amazing visual experience.Program. With WPF, you can create a wide range of independent applications and applications hosted by browsers. At its core, WPF is a vector-based rendering engine that is independent of resolution, designed to take advantage of modern graphics hardware. WPF extends this core through a set of application development features, including eXtensible Application Markup Language (XAML) controls, data binding, layout, 2D and 3D graphics, animations, styles, templates, documents, media, text, and layout.

Advantages over winform

1. All WPF operations do not rely on GDI and GDI +, but indirectly rely on powerful direct3d. This means that using WPF, you can make visual effects that were previously unimaginable by winfrom, applications that include 3D effects. Currently, the latest graphics GPU supports DirectX 11. It is also very easy to implement brilliant 3D effects through WPF.

2. WPF completely separates the program architecture, business logic, and user interface (UI). The WPF engine interprets the UI elements described in XAML as corresponding. to create corresponding controls in the application. Both the UI staff and the program staff can edit and load the controls to completely separate the user interface from the program architecture, winform cannot do this.

WPF has a strong user experience, a simple and convenient deployment method (easy to update and upgrade), a simpler programming method, and a simpler effect. Today, more and more software vendors begin to adopt WPF as the application development model. Some desktop applications developed based on WPF also enter our field of view, such as wpf qq. At the same time, the world's major control manufacturers have also launched a WPF-based user interface control package to provide user interface solutions in a more elegant, simple, and efficient control mode. When we are faced with so many WPF controls, it is indeed difficult to choose the WPF controls suitable for our own software. Below I will make some comparisons and introductions on the four mainstream WPF controls, it is helpful to select the WPF control.

Changes in development mode and team collaboration

Winform development mode: requirement-> Design-> Development (function and interface design [achieve special effects through images or GDI Based on the Interface Effects designed by the artist])-> test-> delivery

WPF development mode: requirement-> Design (function design and interface design)-> Development (function development) and design (interface design [template and style implementation]) -> test-> delivery

Summary: It is mainly reflected in the development and design stages. After the design and development personnel are designed from the original design personnel, the developers need to achieve special results. In addition to writing basic functional code, developers also need to write code for interface effects. Using blend and other functions, WPF allows the interface designer to convert the effects designed to The XAML language. Developers only need to use the mvvm programming mode to write the business logic code, instead of updating the view by following up the name of the interface control. Binding is one of the most distinctive parts of WPF.

System Design

Winform: You need to write the code that calls the business logic in the interface content. In this way, when the business logic changes, we need to modify the page and the code in the interface. Or, if we modify the business layout without modifying the business logic, we also need developers to complete the process.

WPF: with WPF, the two cases above will not be so complicated. 1. When the business logic changes, you only need to modify the relevant code in viewmodel. 2. When the business logic does not change, any modifications to the interface can be completed by the interface designer so that they can perform their respective duties and collaboration.

Future Development

In terms of Microsoft's future development direction, Windows 8's Metro-style touch applications are programmed using the XAML language. Basically, those familiar with WPF are not easy to get started, on Windows phone8, developers familiar with WPF are also easy to switch to WP development, because the basic difference is the syntax, which is generally not that difficult. Therefore, if you have mastered WPF, you will have mastered a foundation. In the future, you will be able to quickly learn the foundation of new technologies, and keep learning with Microsoft.

WPF also has disadvantages

There are many advantages and disadvantages of WPF. The UI thread mode of WPF is also obvious. For friends who are not familiar with multithreading, there will be some problems at the beginning of learning, WPF is not as efficient as winform. Besides, the interface effect is not as good as that of winform. If the person who does not design the interface and the page designed is not as good as that of winform. As far as simple desktop applications are concerned, winform is not as fast as winform. However, WPF is recommended for its powerful features and advantages, which greatly improves the user experience and is especially suitable for desktop applications.

WPF

WPF has the same interface style and control style. As long as it is a custom method that you can think of, you can perform custom control and powerful animation support, let us deeply love this technology. We are currently using a large number of WPF technologies in our projects. When we first started to learn about WPF, it is often easy to fall into the winform programming mode, that is, Drag and Drop controls, then, name the control and operate the control in the background code. This mode is only suitable for simple applications. Anyone familiar with WPF knows that using mvvm can solve this problem, once you have mastered the mvvm, routing, command, and dependency attributes, you can imagine and play the effects of controls, bindings, custom animations, and custom interfaces in WPF. Maybe the sky is your limit, but in actual enterprise applications, it is more in line with the user's habits, so we are closer to the user's usage habits during design.

 

WPF helloword!

1. Create a project (subject to vs2010)

2. After creating a WPF application, the following interface appears:

3. Add some controls on the interface.

4. Compile the event processing code for the button:

5. Run F5 to view the effect. After clicking the button, will the specific effect pop up based on the content entered in the text box?

6. The effect is achieved. However, the form is not centered and does not look beautiful.

Modify the following attributes.

We only need to modify windowstartuplocation to: After centerscreen is modified, let's look at the changes to the XAML code.

Run again and view results

WPF-Start Operation Control

Sometimes, we want our clients to run only one application on the same machine, or do some operations before the program starts. What should we do, let's take a look at the running mechanism of WPF.

1. Override the onstartup method in the app. XAML file.

First,

Second,

Base. onstartup (E); it must be executed before other code.

You can perform some business processing or initialization processing before show.

2. Run the mainwindow form in WPF using the main function in program.

Specific Code:

After running the program, as with the previous running results, the specific code will not be pasted here.

WPF-UI thread

Ui controls in WPF. If we explore the essence, they all inherit from dispatcherobject, so they must be scheduled and used by the UI thread, if we operate interface-related elements in other background threads, the following exception occurs:

An exception occurs after the instance is started.

The method to modify the current error is to call the dispatch object of the UI thread for UI scheduling and execution.

After the modification is complete, you can see that the operation is correct.

We need to know that it is still executed by the UI thread. We need to pay special attention to multithreading programming in WPF. In the subsequent mvvm programming process, we also need to pay attention to this issue when binding the source object in the viewmodel.

Summary

In general, WPF is easy to get started. If you are familiar with winform, it is easy to learn about WPF. However, you still need to work hard on the new features and features of WPF, continuous learning and application can perfectly master WPF. To be continued

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.