【问题标题】:Error Occurred Loading Resource Dictionary加载资源字典时发生错误
【发布时间】:2015-06-24 19:33:06
【问题描述】:

我查看并尝试了我找到的这些othersolutions,甚至复制了Telerik's Documentation。但是,我仍然无法获得有效的解决方案。

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 给出的错误图像:

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

这是程序集属性的图像:

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

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: 

【问题讨论】:

    标签: c# wpf telerik


    【解决方案1】:

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

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

    话虽如此,您在DataVisualization 中缺少ResourceDictionary。如果这不能解决问题,请继续阅读。

    最后我记得,当我在使用 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" />
    

    与往常一样,开始一个新项目并获得这样的基本功能可能会让您感到惊奇,它还会阻止您更改当前代码库中的许多内容,以至于您最终会忘记已更改的内容并在你不想要的地方造成问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多