a simple description of XAML
XAML is the markup language used to instantiate. NET objects, and each element of the user interface XAML that is used primarily to build WPF is mapped to an instance of the. NET class, such as <Button> A button object that is mapped to WPF XAML can nest another element within one element, such as a grid element that can nest a BUTTON element
Understanding XAML
VisualStudio creates a window that, by default, produces the following code: This code contains two markup elements, one window, one gridwindow is a WPF top-level element, and two other top-level elements page and application
Window |
Used to describe a window |
Page |
Similar to window, but it is used for navigable applications |
Application |
Used to define application resources and startup settings |
Any XAML document can have only one top-level element
Property
window labels The title, Height, Width are the properties of the Window property in the XAML file, the type of the value of the property is always a string, but the XAML parser can convert these strings to any type of. NET
Name space
In the above code, the xmlns attribute is used to mark which namespace this document belongs to and why does it need a namespace? If we define the window class in a third-party component, and if there is no namespace to qualify, the compiler does not know which window type we will use to render the windows. We see two namespaces in the code above, one is the WPF core namespace, one is the XAML namespace
WPF core namespaces |
Http://schemas.microsoft.com/winfx/2006/xaml/presentation contains all WPF classes, contains controls to build the user interface, and is the default namespace for the document |
XAML Namespace |
Http://schemas.microsoft.com/winfx/2006/xaml contains a variety of XAML practical features that can affect how the document is interpreted, which is mapped to prefix x, which needs to be labeled with prefix x before use, such as: <x: Elementname> |
With namespace qualification, the <Grid> tag we write directly can be mapped to the System.Windows.Controls.Grid class.
Code-behind class
XAML creates the user interface, but the interaction rules are still required. NET language The X:class property marks the. NET class that is associated with the XAML file. This class is called the InitializeComponent method in the constructor of a partial class, which is responsible for creating control objects, setting properties, binding events, Constructs the user interface and so on work
Complex properties
The
value of some properties is not a simple type, but an object, rather than the background color of the grid below
Now we just have to know that the XAML parser can also create values for complex properties
Markup extension
if we want to bind the property value to an already existing object, then we can use the static Markup extension markup extension There are a lot of other uses, we will talk about here also involves the property binding, we'll talk later
Attached properties
for nested elements, child elements can use some of the attributes defined by the parent element, which is an attached property that is attached to a property in WPF more for layout
Modify a record
2015-1-5: Complete full content
References
"Pro WPF 4.5 in C # 4th Edition" MSDN
Note
This article simply describes the common knowledge of XAML, and there are some uncommon knowledge, advanced topics that are not currently involved
in
Learning wpf--Understanding XAML in WPF