I'm new to XAML. And I wonder what all the x: and :x are all about. Tutorials about XAML does not explain this (or I haven't read enough yet).
For example:
<Window x:Class="WpfTutorialSamples.WPF_Application.ResourceSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="ResourceSample" Height="150" Width="350">
<Window.Resources>
<sys:String x:Key="strHelloWorld">Hello, world!</sys:String>
</Window.Resources>
<StackPanel Margin="10">
<TextBlock Text="{StaticResource strHelloWorld}" FontSize="56" />
<TextBlock>Just another "<TextBlock Text="{StaticResource strHelloWorld}" />" example, but with resources!</TextBlock>
</StackPanel>
</Window>
What does x mean in these lines?
x:Code is a directive element defined in XAML. An x:Code directive element can contain inline programming code. The code that is defined inline can interact with the XAML on the same page. The following example illustrates inline C# code.
The code equivalent of specifying x:Key is the key that is used for the underlying IDictionary. For example, an x:Key that is applied in markup for a resource in WPF is equivalent to the value of the key parameter of ResourceDictionary. Add when you add the resource to a WPF ResourceDictionary in code.
WPF supports techniques that enable specifying the value of some properties of type Type without requiring an x:Type markup extension usage. Instead, you can specify the value as a string that names the type. Examples of this are ControlTemplate.
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 name scope is consistent with the XML 1.0 specification.
This defines a namespace mapping, i.e. the prefix x
maps to the http://schemas.microsoft.com/winfx/2006/xaml
namespace:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Please refer to MSDN for more information about XAML namespaces and namespace mappings.
XAML Namespaces and Namespace Mapping for WPF XAML: https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/xaml-namespaces-and-namespace-mapping-for-wpf-xaml
You might change x
into something else if you want to:
x: meaning in xaml
As mentioned, it is just a prefix that is mapped to a namespace in order for you to be able to use a type or attribute that is defined in the namespace in your XAML markup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With