0

I've a dynamic WPF UI wich is described in xaml.

The xaml can be seen below. My Problem is that my Custom namespaces aren't resolved automatically,

To get the xaml loaded I have to set each assembly with its namespace to the parser context like this

var context = new ParserContext();
context.XamlTypeMapper = new XamlTypeMapper(new string[] { });      

context.XmlnsDictionary.Add("Custom","http://myCompany.de");
context.XamlTypeMapper.AddMappingProcessingInstruction("http://myCompany.de","FooNamespace","FooAssemblyName");

Isn't there a better way? I need this dynamically. And I don't want to scan the app domain.

How is this done in the normal "System Xaml Reader" ?

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:Custom="http://myCompany.de"
    x:Class="Foo.Container" 
    mc:Ignorable="d" 
    d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.DataContext>
        <Custom:FooViewModel/>
    </UserControl.DataContext>
    <Grid>

    </Grid>
</UserControl>
Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
Boas Enkler
  • 12,264
  • 16
  • 69
  • 143

1 Answers1

2
Clr-Namespace URI's without an assembly mentioned only work as compiled Xaml.

But in case you provide assembly with namespaces like - ";assembly=AssemblyName" suffix to your Uri, it will be parse successfully.

But in your case xmlns:Custom="http://myCompany.de", you can't add assembly reference. so, i think the only way out is to add the mapping manually for this case.

And for custom namespaces belonging to your project, you can use the assembly suffix to get them parse.

Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
  • Thanks for info in most of the cases I could use the syntax with the assembly name without url. For Thirdparty controls I wil ladd the reference – Boas Enkler Nov 15 '12 at 15:36