The http://schemas.microsoft.com/winfx/2006/xaml/presentation namespace URI defines all of
the standard WPF controls. The xmlns is equivalent to the using statement in C#. Microsoft
chose this naming scheme because by using a URI with the Microsoft domain, it’s unlikely that
any other developer will use the same URIs when defining namespaces. There are roughly
twelve different standard WPF assembly namespaces and all of them start with
System.Windows. By specifying the URI, the code will search each of the namespaces and
automatically resolve that the Window element maps to the System.Windows.Window class. It
will find the Grid resides in the System.Windows.Controls assembly namespace.
Since line 2 imports the namespace in which all of the WPF elements reside, we do not add a
suffix. Line 3 represents another default WPF namespace that contains many utility classes that
dictate how your XAML document is interpreted. We apply the x suffix to this namespace. Then
to access elements of this namespace, we will prefix the element with x:. For example,
<x:MyElement>.
The following explanation of the xmlns attribute is taken from the XAML Overview (WPF) page
provided on the Microsoft Developer Network documentation on WPF at
https://msdn.microsoft.com/en-us/library/ms752059(v=vs.110).aspx.
The xmlns attribute specifically indicates the default XAML namespace. Within the
default XAML namespace, object elements in the markup can be specified without a
prefix. For most WPF application scenarios, and for almost all of the examples given in
the WPF sections of the SDK, the default XAML namespace is mapped to the WPF
namespace http://schemas.microsoft.com/winfx/2006/xaml/presentation. The xmlns:x
attribute indicates an additional XAML namespace, which maps the XAML language
namespace http://schemas.microsoft.com/winfx/2006/xaml.
This usage of xmlns to define a scope for usage and mapping of a namespace is
consistent with the XML 1.0 specification. XAML namespace is different from XML
namespace only in that a XAML namespace also implies something about how the
namespace's elements are backed by types when it comes to type resolution and
parsing the XAML.
Note that the xmlns attributes are only strictly necessary on the root element of each
XAML file. The xmlns definitions will apply to all descendant elements of the root
element (this behavior is again consistent with the XML 1.0 specification for xmlns). The
xmlns attributes are also permitted on other elements underneath the root, and would
apply to any descendant elements of the defining element. However, frequent definition
or redefinition of XAML namespaces can result in a XAML markup style that is difficult to
read.
The WPF implementation of its XAML processor includes an infrastructure that has
awareness of the WPF core assemblies. The WPF core assemblies are known to
contain the types that support the WPF mappings to the default XAML namespace. This
is enabled through configuration that is part of your project build file and the WPF build
and project systems. Therefore, declaring the default XAML namespace as the default
xmlns is all that is necessary to reference XAML elements that come from WPF
assemblies.