Basic WPF knowledge

Source: Internet
Author: User
Tags silverlight

To learn about WPF, we should focus on the following basic questions: What is WPF? Why WPF? How to Use WPF?

 

First, what is WPF?

WPF is one of the great new programming concepts proposed by M $, short for "Windows Presentation Foundation, it is the technology and tool used to develop the "presentation layer" (the simplest understanding is the program interface.

Someone asked, what should I do with the background logic if WPF only serves as the interface? Answer: Whatever you want. In fact, WPF mainly implements interface-related content. The background logic, including the business logic layer and data layer, is not limited to what technology you use, for example, you can use Microsoft's WCF and WF (you can see the name, this is a set, the great M $ has prepared a big dinner for you from the very beginning, rather than a separate big dish ).

Finally, Let's sum up what is WPF in one sentence. The answer is: interface-based!

Popular concepts: the popular Silverlight has a lot to do with WPF. One saying is that sliverlight is a subset of WPF and is the "network" of WPF ".

 

Second, why WPF?

Superficial reason: the WPF development interface is very nice and cool.

Direct cause: the requirements of the company, customer, boss, and boss.

Indirect cause: M $ spared no effort in promotion.

My personal summary: WPF uses an independent XAML language, so that the development interface is truly separated from the logic after the interface, which brings convenience, for example, designers who are good at modifying interfaces do not have to constantly communicate with programmers who only write code. They only need to master the XAML language to design a very delicate interface (what is the XAML language? ). In addition, I always feel that there seems to be a trend, that is, everything is aligned with the network, WPF is for interface programs, but after using the XAML language, I feel like the HTML page design style is very similar. With the blend provided by Microsoft, designers with webpage design skills can develop various beautiful interfaces in windows; from the network information, the files written in XAML can be called in Windows or accessed by browsers installed with Silverlight, which greatly saves development time, in particular, it blur the boundary between Bs and CS systems, which will make development more efficient for large-scale systems applied to multiple clients (for example, to write a system, you can use Windows PC Desktop programs to access the server, you can also use IE to access the server, or even use a mobile phone to access the server. Their interfaces can be uniformly developed using XAML ).

 

Third, how to use WPF?

This problem seems to be too big. I can only briefly talk about the most basic things here. I thought it was too simple to speak out.

WPF is divided into two parts: The XAML language and the C # code. In WPF, the two parts areIndependentBut againClose contactTogether. Specifically, the XAML language defines the interface elements, while C # implements various message response functions on the interface. For example, if you click a button, the corresponding message response function can be completed in C #, but the shape, color, background, size, and so on of the button itself, it is generally defined in XAML.

Independent: These two parts are placed in different files, with the suffix. XAML and. CS respectively. During development, the interface designer can develop. XAML files while C # programmers develop. CS files.

Close contact: The partial keyword in C # is used in the. CS file to combine a. XAML file with related content in A. CS file to form a class. That is to say, the XAML object defined in each. XAML file can also be considered as a class in C.

Note:: In WPF, some special effects related to message response, such as "move the mouse over the specified control and change the color of the control" can be implemented by C # using message response, however, it can also be implemented through the XAML trigger mechanism. In addition, in C #, you can access the specified control by using the control name defined in XAML and modify its attributes, you can even directly create controls and add them to the interface to control the WPF interface. In this sense, both the XAML master and the C # prawn can complete a beautiful WPF interface, but it is clear that the XAML development interface is obviously more advantageous than the C # interface, after all, you can leave aside the versatility of the Code. Using the blend design, the high efficiency and the brilliant work results are not just as silly as you can think of code. In actual development, designers often use blend to complete the interface, and then the generated XAML code file is handed over to the C # programmer for fine-tuning. Finally, the final interface file is generated.

C # I will not talk about it much. Here I will talk about a basic concept of the XAML language: attribute assignment in two forms.

The XAML language is a subset of the XML language. In other words, the XML language features the XAML. XML flag: defines the values of elements and elements using labels in a tree structure such as <> </>. In XAML, elements in controls and controls are defined, as well as <style> and so on. Note: Like HTML, the settings interface in XAML also uses the markup language. There is a basic concept about the markup language: the attribute value can be assigned by "=" in <>, or the property element can be directly used outside <>) to assign values. The following is a simple example. In this example, the three rows of the grid are defined. The width of each row is 60, and the attribute element used in the first row is, the second row uses the value assignment statement and a string to assign values. The two methods are equivalent. However, you must note that the code is concise when using the value assignment statement. Attribute element assignment applies to complex attributes. For example, in the example code, grid. rowdefinitions can be regarded as a complex attribute of grid, and there are several sub-attributes in the attribute. Such complex attributes are difficult to assign values using simple strings.

Finally, you must note that the value of a string or attribute element should be an object if the attribute element is actually assigned to the attribute. As for how to convert a string or attribute element to an object, you have to ask Microsoft. In fact, if you use C # Instead of XAML, you will find that in many cases, you have to find a way to generate objects to assign values to certain attributes.

<Window x:Class="MyFirstWpfApplication.Win_Test1"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         Title="Win_Test1" Height="300" Width="300">     <Grid>         <Grid.RowDefinitions>             <RowDefinition>                 <RowDefinition.Height>                     60                 </RowDefinition.Height>             </RowDefinition>             <RowDefinition Height="60"/>             <RowDefinition Height="60"/>         </Grid.RowDefinitions>              </Grid> </Window>
Copy code

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.