WPF guide 3 (Name Space of XAML)

Source: Internet
Author: User
In the previous article, it was pointed out that xmlns is used to set the namespace of an XML file. Similarly, xmlns: x is used to specify the namespace. Here, why is x rather than others? We can simply understand that it is just a name for MS and has no special meaning. Of course, to avoid conflicts with it, we cannot define our own namespace as x. Another x: Class is used to support the classes corresponding to the current Window. As mentioned earlier, each XAML element is a CLR type. Here, x: Class is an attribute of Window, the content of the Property indicates that the current window class is Windows1 under the FirstXAML namespace. Why do classes not all need to be implemented using XAML? The main function of XAML is to write the UI part. We still need to use code to control the program logic in a deeper level. Well, this is two basic namespaces. Similarly, namespace can also be customized, and this customization will bring us great convenience. We define the following class: namespace DataBind4Image
{
Public class GroupData
{
// Ignore specific details
}
} If you want to use this GroupData class object in a XAML file, you can introduce this class through a custom namespace: xmlns: local = "clr-namespace: dataBind4Image "the suffix" local "is only an identifier. You can set it to any unique identifier you like. With this introduction definition, we can use local In The XAML file to identify any class in DataBind4Image. When accessing the GroupData class, you only need to add local to identify: <local: DrawingGroupData/> using namespace, in addition to introducing the class of the current project we defined, you can also introduce any Assembly. The example is the simplest: <Window x: Class = "WindowsApplication1.Window1"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: sys = "clr-namespace: System; assembly = System"
>
<ListBox>
<Sys: String> One </sys: String>
</ListBox>
</Window> In the example, the. NET System Assembly is introduced, through which we can directly use any class of System. Using this similar method, we can use almost all DOTNET framework classes in XAML. Finally, it describes how the inline embedded Program Logic processes the code in XAML. Use <CDATA […]> Keyword import processing code. This situation is not suitable in practice. We should not use a mix of UI and logic. For more information, see the Windows SDK documentation.

<! [CDATA [
Void Clicked (object sender, RoutedEventArgs e)
{
Button1.content = "Hello World ";
}
]> </X: code>

As mentioned above, each XAML element represents a. Net CLR class. Most XAML elements are inherited from system. Windows. uielement, system. Windows. frameworkelement, system. Windows. frameworkcontentelement, and system. Windows. contentelement. No XAML element corresponds to the. net clr abstract class. However, many elements correspond to a derived class of an abstract class. There are usually four generic XAML elements: root element: Windows and page are the most commonly used root elements. These elements are located in the root element of the XAML file and contain other elements. Panel element: helps you set the UI position. Stackpanel, dockpanel, grid, and canvas are commonly used. Control Element: defines the control type of The XAML file. Allows you to add and customize controls.
Document element: Helps document submission. It is mainly divided into inline and block element groups to help design similar documents. Some famous inline elements include bold, linebreak, and italic. The block elements include paragraph, list, block, figure, and table.

The property of a XAML element is similar to that of a. NET object. The object-oriented feature of XAML makes its behavior similar to that of a previous HTML object. Each attribute (actually a class attribute) inherits the attribute or overload of the parent element (if the attribute is reset ).

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.