在尝试将ressource字典添加到应用程序的MergedDictionary时,我遇到了解析错误。
System.Windows.Markup.XamlParseException occurred
HResult=-2146233087
Message='Cannot create unknown type '{clr-namespace:Common.UserControls}ButtonVisibilityConverter'.' Line number '4' and line position '6'.
Source=PresentationFramework
LineNumber=4
LinePosition=6
StackTrace:
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, Boolean skipJournaledProperties, Uri baseUri)
at System.Windows.Markup.XamlReader.Load(XamlReader xamlReader, ParserContext parserContext)
at System.Windows.Markup.XamlReader.Load(XmlReader reader, ParserContext parserContext, XamlParseMode parseMode)
at System.Windows.Markup.XamlReader.Load(Stream stream, ParserContext parserContext)
at MS.Internal.AppModel.AppModelKnownContentFactory.XamlConverter(Stream stream, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)
at MS.Internal.AppModel.MimeObjectFactory.GetObjectAndCloseStream(Stream s, ContentType contentType, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean sandboxExternalContent, Boolean allowAsync, Boolean isJournalNavigation, XamlReader& asyncObjectConverter)
at System.Windows.ResourceDictionary.set_Source(Uri value)
at Common.Infrastructure.Bootstrapper.InitializeGlobalRessources() in e:\xxxxx\Common\Infrastructure\Bootstrapper.cs:line 113
InnerException: System.Xaml.XamlObjectWriterException
HResult=-2146233088
Message='Cannot create unknown type '{clr-namespace:Common.UserControls}ButtonVisibilityConverter'.' Line number '4' and line position '6'.
Source=System.Xaml
LineNumber=4
LinePosition=6
StackTrace:
at System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
InnerException:
这似乎指出我的转换器声明出错,但我无法弄清楚原因。
这是我加载的资源
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Common.UserControls">
<local:ButtonVisibilityConverter x:Key="PageButtonVisibilityConverter"/>
....
</ResourceDictionary>
转换器声明:
namespace Common.UserControls
{
public class ButtonVisibilityConverter : IMultiValueConverter{
...
}
}
加载字典的代码: ResourceDictionary dictionary = new ResourceDictionary {Source = new Uri(&#34; / Common; Component / UserControls / Generic.xaml&#34;,UriKind.RelativeOrAbsolute)};
转换器和资源位于同一文件夹中。加载资源的代码位于同一个项目中。
我不知道出了什么问题,因为昨天一切正常,所以我不确定是否因错误引入了更改或是否还有其他问题需要检查?
我已经清除了整个输出目录。
此外,转换器的名称空间声明是由Resharper直接创建的,很少出错。
感谢您的帮助