views:

29

answers:

1

I am trying to generate XAML from XElements.

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

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

Is there a way to control how prefixes of XML namespaces will be generated? Or is it possible to force x:Type markup extension to take XML namespace name instead of prefix?

+1  A: 

I've found that:

new XAttribute(XNamespace.Xmlns + "p", "http://schemas.microsoft.com/winfx/2006/xaml/presentation"); 
TN
Where do you put that attribute?
John Saunders
On any element I want...
TN