【问题标题】:Use an External ResourceDictionary in a WindowsPhone 7/8 app在 WindowsPhone 7/8 应用程序中使用外部资源字典
【发布时间】:2014-03-16 23:10:19
【问题描述】:

我为我的应用程序分离了库,我想将 ResourceDictionary 放在一个位置以将我的默认样式保留。

在构建到 mylib.dll 的项目 mylib 中,我有 Styles/General.xaml:

<ResourceDictionary
x:Class="gjdapi.Style.General"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:System="clr-namespace:System;assembly=mscorlib">

我在我的 App.xaml 中引用它:

<Application.Resources>
    <ResourceDictionary x:Key="General">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/mylib;component/Styles/General.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

Build for Styles/General.xaml 设置为 Page。

我在这里找到了一些提示:

Use an External ResourceDictionary in a WindowsPhone 7 app

xClassNotDerivedFromElement error when adding Code Behind to Resource Dictionary in silverlight

Error using ResourceDictionary in Silverlight

但似乎没有任何效果我总是遇到这个异常:

Message "Parser internal error: Object writer 'xClassNotDerivedFromElement'. [Line: 15 Position: 32]"   string

请告诉我我错过了什么?

【问题讨论】:

  • 如已接受的对引用问题的回答中所述,您的 ResourceDictionary 不能有代码。删除x:Class="gjdapi.Style.General"
  • 删除 x:Class 行后,它起作用了! :) 谢谢

标签: c# silverlight xaml windows-phone-7 windows-phone-8


【解决方案1】:

由于 lisp 建议 ResourceDictionary 后面不能有代码,所以应该删除行 x:Class="gjdapi.Style.General"

【讨论】:

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