开发者

Loading a custom user control with xaml parser

I am trying to load a custom user control into a data template and so far I have the following code.

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

where e.propertyname contains a string. When running this code i get the exception

'rdb' is an undeclared namespace. Line 3, position 30.

Can anyone explain how to properly reference the assembly in this scenario?


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

rdb namespace is declared outside the closing tag for DataTemplate. Shouldn't it be inside the closing tag for DataTemplate like this -

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

Edit: Why can't you have this Template declared in a xaml file and from there you can load it using xaml parser. Try looking at this link- http://blogs.msdn.com/b/ashish/archive/2007/08/14/dynamically-loading-xaml.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜