WPF Loose XAML ResourceDictionary

与世无争的帅哥 提交于 2020-01-04 07:49:10

问题


I am trying to use a ResourceDictionary in loose XAML and load it a runtime to provide templates and styles to a WPF app. I have the XAML available in a local directory and am adding a new ResourceDictionary to App.Current.Resources.MergedDictionaries in app startup using a URI.

When the XAML goes to parse, it blows up on a template where the TargetType is a custom control from the assembly that is consuming it.

The specific message is:

'Failed to create a 'Type' from the text 'controls:CustomType'.'

I already have the namespace mapped in the ResourceDictionary at the top:

xmlns:controls="clr-namespace:TEST.UI.WPF.Common.Controls"

There are articles out there stating that loading ResourceDictionaries from loose XAML is possible but none of them that I have found address custom types within those loose XAML files.

Any help is appreciated!


回答1:


Since you are loading this at runtime and it is not built within the project then the ResourceDictionary does not know of your assembly. You will have to include the assembly in the namespace for it to be recognised.

xmlns:controls="clr-namespace:TEST.UI.WPF.Common.Controls;assembly=Common"

You should be able to run you app after you add ';assembly=yourAssembly' to the namespace declaration.



来源:https://stackoverflow.com/questions/21465443/wpf-loose-xaml-resourcedictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!