WPF<1>_XAML Basic

Table of Contents

1. Three-tier architecture

2. Expression mode and architectural mode


ASP.net is Microsoft’s new generation scripting language, a powerful server-side technology for creating dynamic Web pages.

Avalinia is a powerful framework that enables developers to create cross-platform applications using .NET.

1. Three-tier architecture

1. The architectural pattern consisting of presentation layer, logic layer and data layer is called three-tier architecture.

Presentation layer (UI): Displays data and process results to users.

Business Logic Layer (BLL): Use computer programs to express realistic business logic according to requirements.

Data layer (DAL): used to store data, mostly composed of databases, and sometimes data files are used to assist in storing data.

The idea of high cohesion and low coupling divides the program into functional blocks.

2. Delimitation of data operation layer

a. When the logic code of data operation is placed in the business logic layer, data access becomes a kind of business logic. The presentation layer’s access to data calls the same method as the business logic layer’s corresponding data operations.

b. When storing all data reading operations in the data layer, you only need to define another method in the business layer for the presentation layer to call.

C. Entity class

Between the modules of each layer of the three-tier architecture, the entity classes of the object model are used as the carrier of data transfer. The entity classes of different object models generally correspond to different tables of the database, and the attributes of the entity classes are consistent with the field names of the database tables.

2.Performance model and architectural model

Performance mode:

Improve the way your code is organized by separating concerns. Expression patterns focus on solving code organization and often use multiple design patterns, so they are also called composite design patterns.

Design Patterns:

An abstract method summarized to solve a type of problem.

Architecture pattern:

Describe the basic structural organization or outline of a software system. Architectural patterns provide a set of well-defined subsystems, specify their responsibilities, and give rules and guidelines for organizing them together.

3.MVC mode

The MVC pattern is a guiding pattern for GUI interface development. It divides the program into three parts based on the idea of functional division of the presentation layer.

The design purpose of MVC is to realize the planning of functional structure.

Model: handles program logic, obtains and stores data.

View: displays data and provides user interaction interface.

Controller: handles user interaction, reads data from View, and sends data to Model.

4.MVVM mode

MVVM is Model-View-ViewModel. It is a presentation model based on front-end development. Its core is to provide two-way data binding between View and ViewModel, which allows the state changes of ViewModel to be automatically passed to View.

Vendor dependencies between various parts in MVVM mode

1.ViewMode can directly obtain Model information

2. The model cannot directly obtain ViewModel information

3. ViewModel cannot directly obtain View information.

5. Division of program functions in the presentation layer

1. Data model: realizes the abstraction of things and logic in the world.

2. Business logic: relationship interaction between data models.

3. User interface: An interface composed of controls that interacts with the user. It is used to display data to the user and respond to the user’s operations.

4. Interface logic: the relationship and interaction logic between controls.

6. Event-driven

Event-driven programs are organized through the relationship of “event-subscription-event processing”. Under event-driven, every operation performed by the user will trigger an event in the program. After the event is sent, the event processor used to respond to the event will be executed.

7. Data driven

Under the data-driven concept, data takes the initiative, that is, the content determines the form. The data-driven bridge is a two-way data binding. Data Binging can realize data flow to the interface, and the interface can also flow events to the data source.

8.XAML Overview

XAML is a new extensible application markup language. It is a language specifically used for designing UI in WPF. It is a pure declarative language.

The XAML language serves as an alternative to programming code for instantiating and initializing objects, as well as organizing these objects in parent-child hierarchies.

9. Declaration tag

In the XAML language, tags are used to declare an element, and each element corresponds to an object in memory. The element’s attributes and content can be further declared through the tag’s syntax. There are two forms of expression.

<Tag Attribute1="vALUE1" Attribute2="value2">Content</Tag> <!--Non-empty tag-->
<Tag Attribute1="vALUE1" Attribute2="value2" /> <!--Empty tag-->

<Grid> <!--Content starter-->
</Grid>
<Window/> <!--End tag -->
Characteristics and attributes

Some characteristics of the element will be mapped to some attributes

Attributes: Members of a class used to represent the state of things, which are data expressions of abstract models of real things in the program.

Features: Characteristic expressions used to distinguish elements at the language expression level, and have nothing to do with abstract objects.

XMLNS

xmlns is XML-Namespace. One of its advantages is that when the sources referenced by Yao have different classes with the same name, namespaces can be used to distinguish them. The syntax of namespaces in XAML is different from C#. In C#, we use the using keyword to call the namespace at the top of the code. The syntax format in XAML is:

xmlns="[namespace]" <!--No mapping prefix-->


xmlns=[mapping prefix]="[namespace]" <!--has mapping prefix-->

When using XAML syntax to declare element tags, the relationship between the corresponding declared objects and the objects is either inclusion or parallel relationship, so we also say that the syntax structure of XAML is a numerical inclusion or parallel structure.

Rectangle class

The class used to draw rectangles in WPF is the Rectangle class. The modified class has a Fill property for color filling the rectangle. The assignment type of Rectangle.Fill is Brush.Brush, which is an abstract class. Its shooting classes include solid color brush (SolidColorBrush), linear gradient brush (LinearGradientBrush) and bitmap brush (ImadeBrush), etc.

Principle discussion

If XAML is used to declare characteristics of attributes of a class, there must be an assignment mechanism in the logic code to convert the characteristic assignment string into attribute value.

Characteristics are declared in XAML using strings. If complex assignments or internal precise assignments are required for properties, it will be very difficult for XAML designers to write conversion mechanisms for this purpose.

Simplification of XAML attribute assignment

In order to make XAML expression as simple as possible, we should follow the following rules as much as possible:

If you can use direct feature assignment, do not use the form of element attribute assignment.

Take advantage of defaults.

The shorthand form of XAML is allowed.

10. Tag extension (data binding)

XAML markup extensions form an important feature in XAML, allowing attributes to be represented as objects or values that are indirectly referenced from other sources. XAML markup extensions are particularly important for sharing objects and referencing constants used throughout your application, but they find their greatest utility in data binding.

PS: Data binding, such as sliding elements, the corresponding value can be changed in both directions.

11.Event handling

In the event processing mechanism of .NET, you can specify a member method that can match the event for an event of the object. When this event occurs, the NET runtime will call this method to indicate the response and processing of this event. .

<Button Morgin="5" Content="OK" Click="Button_Click"/>

The Click event program is automatically generated in the corresponding CS code.

12.XAML comments

1. Comments can only appear in the content area of the label.

2. Annotations cannot be used to comment out label feature assignments.

3. Comments cannot be nested.

13.XAML advantages

1. Common code is simpler and more readable than equivalent code

2. Simulate the parent-child hierarchy of user interface objects with greater visual clarity.

3. The program is easy to write manually, but also makes it an operability and generation tool for visual design tools.

14.Blend design user interface visualization tool