【发布时间】:2021-10-16 15:44:17
【问题描述】:
晚上好。请提出 WPF XAML 资源问题。
我有一个名为 Resources 的用户控制项目。在这个项目中,我有一个包含多个 XAML 文件的目录。我已将这些资源合并到项目根目录的 Main.xaml 文件中。
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources;component/xaml/Buttons.xaml" />
<ResourceDictionary Source="Resources;component/xaml/Images.xaml" />
<ResourceDictionary Source="Resources;component/xaml/Styles.xaml" />
<ResourceDictionary Source="Resources;component/xaml/Tooltips.xaml" />
</ResourceDictionary.MergedDictionaries>
Resource 项目编译没有问题,并且您在上面看到的代码中没有视觉错误。
我还有一个名为 Buttons 的项目。在 App.xaml 中,我引用了这个 Resource 项目。
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Resources;component/Main.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
我在 Button 项目中引用了 Resources.dll。 Visual Studio 在 ResourceDictionary 语句下显示错误行;项目是如何编译的。
当我运行 Button.exe 时,我收到错误消息“无法找到资源 'resources;component/xaml/buttons.xaml'。”
我的 ResourceDictionary 语句与我在其他项目中成功完成的相匹配。假设我在 Button 项目中的 App.xaml 中编写的内容是正确的,我应该在 Resources 的 Main.xaml 文件中做些什么不同的事情?
提前致谢。
【问题讨论】:
标签: wpf xaml resourcedictionary