For example, the Window class could exist in several
places??”it might refer to the System.Windows.Window class, or it could refer to a Window
class in a third-party component, or one you??™ve defined in your application. To figure out
which class you really want, the XAML parser examines the XML namespace that??™s applied to
the element.
Here??™s how it works. In the sample document shown earlier, two namespaces are defined:
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
nNote XML namespaces are declared using attributes. These attributes can be placed inside any element
start tag. However, convention dictates that all the namespaces you need to use in a document should be
declared in the very first tag, as they are in this example. Once a namespace is declared, it can be used
anywhere in the document.
The xmlns attribute is a specialized attribute in the world of XML that??™s reserved for
declaring namespaces. This snippet of markup declares two namespaces that you??™ll find in
every WPF XAML document you create:
CHAPTER 2 n XAML 28
??? http://schemas.microsoft.com/winfx/2006/xaml/presentation is the core WPF namespace.
It encompasses all the WPF classes, including the controls you use to build user
interfaces.
Pages:
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123