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>

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.