新手入门XAML。x:和:x是什么意思?

8

我对XAML很陌生,不知道所有的"x:"和":x"都是什么意思。关于XAML的教程也没有解释这些内容(或者我还没有读够)。

例如:

<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>

这些行中的x是什么意思?

  • Window x:Class="WpfTutorialSamples.WPF_Application.ResourceSample"
  • xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" sys:String
  • x:Key="strHelloWorld">Hello, world!
1个回答

13
这定义了一个命名空间映射,即前缀x映射到http://schemas.microsoft.com/winfx/2006/xaml命名空间:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

请参考 MSDN 了解有关 XAML 命名空间和命名空间映射的更多信息。
WPF XAML 的 XAML 命名空间和命名空间映射:https://learn.microsoft.com/zh-cn/dotnet/framework/wpf/advanced/xaml-namespaces-and-namespace-mapping-for-wpf-xaml 如果您想要,可以将 x 更改为其他内容: x: 在 XAML 中的含义 正如所提到的那样,这只是一个前缀,它被映射到一个命名空间,以便您能够在 XAML 标记中使用在该命名空间中定义的类型或属性。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接