0

xamlで記述されている動的なWPFUIがあります。

xamlは以下に表示されます。私の問題は、カスタム名前空間が自動的に解決されないことです。

xamlをロードするには、名前空間を持つアセンブリを次のようにパーサーコンテキストに設定する必要があります

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");

もっと良い方法はありませんか?これは動的に必要です。そして、私はアプリのドメインをスキャンしたくありません。

これは通常の「SystemXamlReader」でどのように行われますか?

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

1 に答える 1

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

ただし、";assembly=AssemblyName"Uriに-suffixのような名前空間を使用してアセンブリを提供すると、正常に解析されます。

ただし、あなたの場合xmlns:Custom="http://myCompany.de"、アセンブリ参照を追加することはできません。したがって、この場合、マッピングを手動で追加するのが唯一の方法だと思います。

また、プロジェクトに属するカスタム名前空間の場合、assembly接尾辞を使用してそれらを解析できます。

于 2012-11-15T15:04:05.070 に答える