WPF: WPF and XAML namespace declarations

This entry is part 12 of 54 in the series Learn WPF

In our earlier posts, in the MainWindow.xaml file, we see that there are 2 lines related to xmlns.  xmlns means xml namespace.

In this post, we look at the presence and purpose of the two XAML namespace mappings as they are commonly found in the root tag of a WPF XAML file.

MainWindow.xaml

<Window x:Class="SayHello.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="500">
    <Grid>

    </Grid>

</Window>

The first declaration maps the overall WPF namespace as the default:

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

It is the default XML namespace and it is mapped to the normal WPF namespaces such as System.Windows, System.Windows.Controls and so on.

The second declaration maps a separate XAML namespace, mapping it to the x: prefix.

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

An example XAML namespace that it maps to is System.Windows.Markup.

Series Navigation<< WPF: Data binding
WPF: A simple checkbox >>

Leave a comment

Leave a Reply