繁体   English   中英

加载资源字典时出错

[英]Error Occurred Loading Resource Dictionary

我查看并尝试了我发现的其他解决方案,甚至复制了Telerik 的文档 但是,我仍然无法获得有效的解决方案。

XAML:

    <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="NotifyIconResources.xaml" />
            <ResourceDictionary Source="pack://application:,,,/Telerik.Windows.Themes.Windows8;component/Themes/System.Windows.xaml" />
            <ResourceDictionary Source="pack://application:,,,/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/Telerik.Windows.Themes.Windows8;component/Themes/Telerik.Windows.Controls.Navigation.xaml" />
        </ResourceDictionary.MergedDictionaries>

这是 ReSharper 给出的错误图像:ReSharper 图像

这是作为参考的程序集图像:组装作为参考

这是程序集属性的图像:装配属性

最后,这是我尝试运行应用程序时的异常信息:

System.Windows.Markup.XamlParseException was unhandled
  HResult=-2146233087
  Message='Cannot create unknown type '{clr-namespace:Telerik.Windows.Controls.External}Windows8ThemeExternal'.' Line number '15' and line position '6'.
  Source=PresentationFramework
  LineNumber=15
  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.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
       at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       at MyApp.App.InitializeComponent() in App.xaml: line 1
       at MyApp.App.Main() in c:\MyApp\obj\Debug\App.g.cs: line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Xaml.XamlObjectWriterException
       HResult=-2146233088
       Message='Cannot create unknown type '{clr-namespace:Telerik.Windows.Controls.External}Windows8ThemeExternal'.' Line number '15' and line position '6'.
       Source=System.Xaml
       LineNumber=15
       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: 

根据 Telerik 文档,我知道的第一件事是错误的,必须添加,

它们可以合并到应用程序的资源中(在 App.xaml 中),因此将隐式应用于没有本地样式集的任何控件。 例如,如果需要从 Telerik.Windows.Controls.dll 设置控件的样式,则需要 Telerik.Windows.Controls.xaml 资源字典。

也就是说,您缺少DataVisualizationResourceDictionary 如果这不能解决问题,请继续阅读。

最后我记得,当我使用 Telerik 查看我的应用程序的主题时,有几种不同的方法可以应用样式,而且一开始做正确可能有点棘手。 有隐式样式 (NoXaml) 和标准样式,其中样式内置于控件库中。 隐式样式是推荐的以“全局”方式设置应用程序样式的方法。 IIRC,它的性能也更高,代码也更干净。

由于我们在 WPF 聊天中进行了交谈,因此您似乎不确定要尝试从源代码构建哪些二进制文件。 隐式样式要求您构建 Binaries.NoXaml 源代码。 说了又做之后,您必须确保添加对来自..\\Binaries.NoXaml\\WPF4x\\目录的正确程序集的引用。

我上次从源代码构建时,构建说明包含在下载的 .ZIP 中。 确保仔细遵循这些说明。 我没有使用内置的 Visual Studio Telerik 工具来构建/部署我引用的库,所以如果你是,那么也许手动是要走的路。

其他一些事情。 我怀疑构建没有成功完成。 您在 Telerik 参考中的版本号应该不是0.0.0.0 其次,如果我没记错的话,我在定义源时遇到了问题,可能顺序很重要——所以请尝试我在下面的示例中使用的源,并可能将NotifyIconResources.xaml移动到 Telerik 声明下方。

这是我使用隐式样式技术的 XAML:

<ResourceDictionary Source="/Telerik.Windows.Themes.Windows7;component/Themes/Telerik.Windows.Controls.xaml" />
<ResourceDictionary Source="/Telerik.Windows.Themes.Windows7;component/Themes/System.Windows.xaml" />
<ResourceDictionary Source="/Telerik.Windows.Themes.Windows7;component/Themes/Telerik.Windows.Controls.Input.xaml" />
<ResourceDictionary Source="/Telerik.Windows.Themes.Windows7;component/Themes/Telerik.Windows.Controls.Navigation.xaml" />

与往常一样,开始一个新项目并获得像这样的基本工作可能会让您感到奇怪,它还会阻止您更改当前代码库中的太多内容,从而最终忘记您更改的内容并导致问题你不想要的地方。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM