How to manage namespace prefixes in an XML document generated by XmlWriter-generated XAML with x markup extension: Type

I am trying to create XAML from XElements.

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

However, I have a problem with the markup extension x:Type. It cannot resolve the prefix p:because I do not know how to make the output XAML map the prefix pto the namespace http://schemas.microsoft.com/winfx/2006/xaml/presentation.

Is there a way to control how XML namespace prefixes are generated? Or is it possible to force the markup extension x:Typeto use the XML namespace name instead of the prefix name?

+3
source share
1 answer

, :

new XAttribute(XNamespace.Xmlns + "p", "http://schemas.microsoft.com/winfx/2006/xaml/presentation"); 
+1

Source: https://habr.com/ru/post/1754694/


All Articles