如何控制 XmlWriter 生成的 XML 文档中命名空间的前缀 - 使用 x:Type 标记扩展生成的 XAML

StackOverflow https://stackoverflow.com/questions/3250466

我正在尝试从 XElements 生成 XAML。

<Style xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <Style.BasedOn>
    <StaticResource> 
      <StaticResource.ResourceKey>
        <Type xmlns="http://schemas.microsoft.com/winfx/2006/xaml">
          <Type.TypeName>p:Window</Type.TypeName> 
        </Type>
      </StaticResource.ResourceKey>
    </StaticResource>
  </Style.BasedOn>
  ...
</Style>

但是,我有问题 x:Type 标记扩展。无法解析前缀 p:, ,因为我不知道如何强制输出 XAML 映射前缀 p 到命名空间 http://schemas.microsoft.com/winfx/2006/xaml/presentation.

有没有办法控制 XML 命名空间前缀的生成方式?或者是否可以强制 x:Type 标记扩展采用 XML 命名空间名称而不是前缀?

有帮助吗?

解决方案

我发现:

new XAttribute(XNamespace.Xmlns + "p", "http://schemas.microsoft.com/winfx/2006/xaml/presentation"); 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top