Wpf 使用xaml解析器加载自定义用户控件

Wpf 使用xaml解析器加载自定义用户控件,wpf,xaml,Wpf,Xaml,我正在尝试将自定义用户控件加载到数据模板中,到目前为止,我有以下代码 var xaml = @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:rdb='clr-namespace:Admintool.UI.ResourceEditorWpf;assembly=program1.exe

我正在尝试将自定义用户控件加载到数据模板中,到目前为止,我有以下代码

   var xaml = @"<DataTemplate   xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
                                     xmlns:rdb='clr-namespace:Admintool.UI.ResourceEditorWpf;assembly=program1.exe' >
                        <rdb:MaskedLabel
                            Content='{Binding " + e.PropertyName + "}'></rdb:MaskedLabel> </DataTemplate>";

        var stringReader = new StringReader(xaml);
        var xmlReader = XmlReader.Create(stringReader);
        var cellTemplate = (DataTemplate)XamlReader.Load(xmlReader);
有人能解释一下在这种情况下如何正确引用程序集吗


<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> 
 xmlns:rdb='clr-namespace:Admintool.UI.ResourceEditorWpf;assembly=program1.exe'
xmlns:rdb='clr-namespace:Admintool.UI.ResourceEditorWpf;assembly=program1.exe'
rdb命名空间在DataTemplate的结束标记之外声明。它不应该像这样位于DataTemplate的结束标记中吗-

<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
              xmlns:rdb='clr-namespace:Admintool.UI.ResourceEditorWpf;assembly=program1.exe'>

编辑: 为什么不能在xaml文件中声明此模板,然后使用xaml解析器从中加载它呢。请尝试查看此链接-

oops这是一个问题的输入错误,xaml仍然会抛出这个错误
<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
              xmlns:rdb='clr-namespace:Admintool.UI.ResourceEditorWpf;assembly=program1.exe'>