Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

What is xmlns?

What role does it play in an XAML file when we create a WPF project?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
724 views
Welcome To Ask or Share your Answers For Others

1 Answer

xmlns is an XML, not necessarily XAML, construct which defines a namespace in which to resolve xml element names. Because it is defined without a qualifier, it is defining the default namespace by which an XML element name should be resolved.

In XAML you usually see the following entry. It defines the default namespace to be essentially WPF and all XML element names are hence resolved as WPF elements.

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

It's also common to see non-default namespaces such as the following.

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

This defines a qualified namespace for XAML specific elements. If you want an element or attribute name to be resolved within this namespace you should qualify it with x. For example

<StackPanel x:Name="foo" />

There are 2 name resolutions in this definition.

  1. StackPanel - Because it's an unqualified name, it will be resolved in the default namespace which is WPF
  2. x:Name - Name is qualified with x and will be resolved within the XAML document.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...