场景:在WPF中读取ResouceDictionary中自定义的对象
例子:
修改前的Xaml
1<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3 xmlns:list="clr-namespace:Disappearwind.BlogSolution.BlogTools">
1<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3 xmlns:list="clr-namespace:Disappearwind.BlogSolution.BlogTools">
错误描述:"Missing XmlNamespace, Assembly, or ClrNamespace in Mapping instruction. Line '3' Position '5'."
原因:自定义对象的引用有问题,除了要引用对象的类型信息外还需要引用程序集信息:
修改后的代码
1<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3 xmlns:list="clr-namespace:Disappearwind.BlogSolution.BlogTools;assembly=Disappearwind.BlogSolution.BlogTools">
1<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3 xmlns:list="clr-namespace:Disappearwind.BlogSolution.BlogTools;assembly=Disappearwind.BlogSolution.BlogTools">
注意assembly=后面的就是程序集的信息。