0

我们有一个控制库,我们在主应用程序中引用它。在其中,我们决定将 Generic.xaml 拆分为特定于类型的资源,例如 Brushes.xaml、Colors.xaml 等,然后我们只需将它们合并到 Generic.xaml 中。我们在 Themes 目录中将它们创建为 Generic.xaml 的兄弟姐妹,我们知道您应该在本地相对引用它们,就像这样......

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>

这是类库的 AssemblyInfo.cs 中的属性

[assembly:ThemeInfo(
    // Where theme specific resource dictionaries are located
    // (used if a resource is not found in the page, or application resource dictionaries)
    ResourceDictionaryLocation.None,

    // Where the generic resource dictionary is located
    // (used if a resource is not found in the page, app, or any theme specific resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly
)]

...但它会引发以下异常...

{"Cannot locate resource 'brushes.xaml'."}

(请注意,小写也是例外。奇数。)

现在我尝试了“Brushes.xaml”、“Themes/Brushes.xaml”和“/Themes/Brushes.xaml”,但无济于事。我到底错过了什么?

注意:如果资源与应用程序位于同一程序集中,它似乎可以工作。这似乎仅与将资源分离到类库中有关。

4

1 回答 1

0

找到了。Generic.xaml 具有特殊规则,您必须使用完全限定的源。这有效...

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/ControlLibrary;component/Themes/Brushes.xaml" />
</ResourceDictionary.MergedDictionaries>
于 2015-05-23T08:23:18.033 回答