Learning WPF-learn about XAML in WPF and wpfxaml
A brief description of XAML
XAML is used for instantiation.. NET object markup language, which is mainly used to build the WPF user interface. every element in the XAML is mapped. an instance of the. NET class. For example, the <Button> Button object mapped to wpf xaml can nest another element in one element. For example, the Grid element can nest the Button element.
Learn about XAML
Create a window in Visual Studio. The code generated by default is as follows:WindowUsed to describe a windowPageSimilar to Window, but it is used for applications that can be navigatedApplicationUsed to define application resources and startup settingsAny XAML document can have only one top-level element
Attribute
In the window tag, Title, Height, and Width are all window attributes. In The XAML file, the attribute value type is always a string, but the XAML parser can convert these strings to any. NET type.
Namespace
In the code above, the xmlns attribute is used to mark which namespace this document belongs to. Why does it need a namespace? If we define the Window class in a third-party component, if there is no namespace to limit it, the compiler does not know which Window type we will use to render the Window. In the code above, we can see two namespaces: the WPF core namespace and The XAML namespace.
WPF core namespace |
Bytes |
XAML namespace |
Principal <x: ElementName> |
With the namespace limitation, we can directly write the <Grid> label to map it to the System. Windows. Controls. Grid class.
Code hiding class
The user interface is created in XAML, but the interaction rules still need to be written in. NET language. The x: Class Attribute marks the. NET Class complex attributes that match the XAML file.The value of some properties is not a simple type, but an object. The background color of the Grid below is not as good
Tag ExtensionIf we want to bind the property value to an existing object, we can use static tag to extend the additional property.For nested elements, child elements can use some attributes defined by the parent element. These attributes are additional attributes in WPF and are mostly used for layout.
Modify record: Complete all content References《Pro WPF 4.5 in C# 4th Edition》MSDN Remarks This article only briefly introduces the common knowledge of XAML, but also some uncommon knowledge. The advanced topic is not involved at the moment. |
|