首页 文章

XAML新手 . x:和x是什么意思?

提问于
浏览
2

我是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">你好,世界!

1 回答

  • 4

    这定义了名称空间映射,即前缀 x 映射到 http://schemas.microsoft.com/winfx/2006/xaml 名称空间:

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

    有关XAML命名空间和命名空间映射的更多信息,请参阅MSDN .

    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

    如果您愿意,可以将 x 更改为其他内容:

    x: meaning in xaml

    如上所述,它只是一个映射到命名空间的前缀,以便您能够使用XAML标记中命名空间中定义的类型或属性 .

相关问题