WPF Step by Step Series-opening

Source: Internet
Author: User

What the WPF series contains
    • Introduction to WPF Basics
    • Introduction to WPF Layouts
    • Introduction to WPF Controls (contains third-party controls)
    • WPF Custom Templates
    • WPF dependency properties, routed events
    • MVVM Programming for WPF
    • WPF Development Framework Prism
    • WPF Development Framework WAF
    • WPF Development Framework Caliburn
Why do we choose WPF? Introduced

Windows Apiwindows Presentation Foundation (WPF) is a next-generation display system that generates a WINDOWS client application that brings a stunning visual experience to the user. With WPF, you can create a wide range of standalone applications and browser-hosted applications. At the core of WPF is a resolution-independent, vector-based rendering engine designed to take advantage of modern graphics hardware. WPF extends this core through a complete set of application development features, including extensible Application Markup Language (XAML), controls, data binding, layout, two-and three-dimensional graphics, animations, styles, templates, documents, media, text, and typography.

Compared to the advantages of WinForm

1. All of WPF's operations do not depend on GDI and GDI +, but indirectly on powerful Direct3D, which means that WPF can make applications that previously winfrom unimaginable visuals, including 3D effects. The latest graphics GPU already supports DirectX 11, and the brilliant, realistic 3D effect through WPF is a very simple thing to do.

2. WPF implementation completely separates the program architecture, business logic and user Interface (UI), The WPF engine interprets the UI elements described in XAML as appropriate. NET objects to create the appropriate controls in the application, and UI staff and program personnel can edit the control to load the user interface and the program schema completely apart, and WinForm this is not possible.

WPF has a strong user experience, simple and convenient deployment method (easy Update upgrade), more simple programming way, to achieve a more simple and beautiful effect of the characteristics. Today more and more software vendors are using WPF as an application development model, and some WPF-based desktop applications also come into our horizons, such as WPF QQ. At the same time, the world's major control vendors have introduced the WPF-based user Interface control package to provide user interface solutions in a more beautiful, simple and efficient control pattern. When we're faced with so many WPF controls, how to choose the WPF control that's right for your software is a challenge, and here's a look at some of the 4 main WPF controls that I want to help with choosing a WPF control.

Development patterns and changes in team collaboration

WinForm Development Model: Requirements---design and development (function and interface design [according to the design of the interface effect, through the image or GDI to achieve special effects]), testing and delivery

WPF development model: Requirements---design (functional design and interface design)--development (functional development) and design (interface design [template and style can be implemented]), testing and delivery

Summary: Mainly embodied in the development and design phase, the design and development staff from the original design staff, developers need to achieve special results. And developers need to write a lot of code, in addition to writing basic functional code also need to write the interface effect code. WPF transforms the design of the interface designer into a XAML language through blend, and developers only need to use the MVVM programming pattern, write business logic code, and not follow the interface control's name again to update the view. With regard to bindings, this piece is one of the most distinctive parts of WPF.

System Design

WinForm: We need to write the code that invokes the business logic in the interface content. Thus, when the business logic changes, we need to modify the page and modify the code within the interface. Or if we modify the business layout and do not modify the business logic, then we need the developer to do it.

WPF: With WPF, the two scenarios above are less complicated, 1, and when the business logic changes, you only need to modify the relevant code in the ViewModel. 2, when the business logic does not change, any changes to the interface, can let the interface designers to complete, so as to achieve their respective responsibilities and collaboration.

Future development

Microsoft's future development direction says, Windows8 's metro style Touch application, uses the XAML language to program the way, basically is familiar with the WPF the friend, has no what to say, the window Phone8, is familiar with the WPF developer, turns the WP development is also relatively easy , because the basic is the grammatical difference, generally not so difficult. So, you have mastered WPF, then you have mastered a foundation, the future can quickly learn the basis of new technology, followed by Microsoft, is to continue to learn.

WPF also has drawbacks

WPF has a lot of advantages, the disadvantage is equally obvious, WPF UI threading mode, for unfamiliar with multi-threaded friends, just beginning to learn, there will be some problems, WPF in want to and run efficiency than WinForm, and, interface effect, if not interface design of the person, design out of the page, It's not as good as the WinForm interface. And on the desktop simple application, not as fast as WinForm, but its powerful features and advantages, or recommended WPF,WPF greatly improve the user experience, especially for desktop applications.

WPF Imagination

WPF on the interface style and control style, can be said to be the same, as long as you can think of a custom way, you can do custom control, powerful animation support, let us be able to love such technology, our current project a large number of use of WPF technology, just beginning to learn WPF, Often easy to fall into the WinForm programming mode, is to drag the control, and then name the control, in the background code to manipulate the control, such a pattern, only for simple applications, familiar with the WPF colleagues know that using MVVM to solve such problems, once you mastered the MVVM, routing, command, After the dependency property, for WPF controls, bindings, custom animations, custom interface effects and so on you can imagine and play freely. Maybe the sky is your limit, but the actual enterprise application, more is more in line with the way users use habits, so we design more close to the user's usage habits.

WPF helloword!

1. New project (whichever is VS2010)

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

3, add some controls on the interface.

4. Write the event handling code for the button:

5, F5 run to see the effect, click the button, whether it will be based on our text box input content, pop-up specific effect?

6, the effect is realized, however, the form is not centered, looks not beautiful.

Modify one of the following properties.

We only need to modify windowstartuplocation modified to: Centerscreen After the modification, we look at the transformation of the XAML code

Run again, view effects

wpf-Start-up Operation control

Sometimes, we want our client, the same machine can only run one application, or the program started before the operation of some operations, then how we do it, we need to work on the operating mechanism of WPF, we will look at the following.

1. Rewrite the Onstartup method in the App.xaml file.

First of all

Secondly

Base. Onstartup (e); Must precede the other code to execute first.

You can do some business processing before the show, or initialize the processing.

2. In program, run the MainWindow form in WPF by using the main function.

The specific code:

After running the program, as in the previous run results, there is no specific code to be posted.

Wpf-ui Threads

UI controls in WPF, if we explore the essence, they all inherit from Dispatcherobject, so all must be dispatched and used by the UI thread, and if we manipulate the interface-related elements in other background threads, the following exception message appears:

After you start the run, there is an exception.

The way to modify the current error is to invoke the dispatch object of the UI thread to schedule and execute the UI.

Once the modifications are complete, run to see the correct run.

We need to know that it will eventually be executed by the UI thread, which requires special attention when we do multithreaded programming in WPF. We also need to be aware of this when we modify the binding source objects in our team ViewModel during the later MVVM programming process.

Summarize

WPF as a whole is relatively easy to get started, familiar with WinForm friends, for learning WPF, it is easy to get started, but will be in the new features and features of WPF need to work hard, continuous learning and application, to be able to master WPF perfectly. Not to be continued

Http://www.cnblogs.com/hegezhou_hot/archive/2012/10/19/2730448.html

WPF Step by Step Series-opening

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.