【问题标题】:New to XAML. What does the x: and :x mean?XAML 的新手。 x: 和 :x 是什么意思?
【发布时间】:2018-01-31 02:02:05
【问题描述】:

我是 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 是什么意思?

  • 窗口 x:Class="WpfTutorialSamples.WPF_Application.ResourceSample"
  • xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" sys:String
  • x:Key="strHelloWorld">你好,世界!

【问题讨论】:

    标签: wpf xaml


    【解决方案1】:

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

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

    有关 XAML 命名空间和命名空间映射的详细信息,请参阅 MSDN。

    WPF XAML 的 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 标记中使用命名空间中定义的类型或属性。

    【讨论】:

      猜你喜欢
      • 2011-05-27
      • 2020-03-18
      • 2021-08-02
      • 2015-03-24
      • 2020-10-02
      • 2018-05-03
      • 1970-01-01
      • 2015-12-30
      • 2018-11-24
      相关资源
      最近更新 更多