wpf MahApps.Metro 找不到资源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20324912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MahApps.Metro cannot find resources
提问by Aleksey Shubin
I am trying to create new WPF application usign MahApps.Metro. I do exactly as described in quick start guide (http://mahapps.com/MahApps.Metro/guides/quick-start.html):
我正在尝试使用 MahApps.Metro 创建新的 WPF 应用程序。我完全按照快速入门指南(http://mahapps.com/MahApps.Metro/guides/quick-start.html)中的描述进行操作:
- Add MahApps.Metro package from Nuget to the project.
- Add xmlns namespace and replaced Window with MetroWindow.
- 将 MahApps.Metro 包从 Nuget 添加到项目中。
- 添加 xmlns 命名空间并将 Window 替换为 MetroWindow。
At this point I can run the application, but the window is transparent. Title bar text and buttons are visible (and buttons are not styled), but the background is transparent.
此时我可以运行应用程序,但窗口是透明的。标题栏文本和按钮可见(并且按钮没有样式),但背景是透明的。
- Add merged dictionaries code for the Window.
- 为 Window 添加合并字典代码。
After that I receive an exception on startup:
之后,我在启动时收到异常:
System.IOException
{"Cannot locate resource 'styles/colours.xaml'."}
Seems as for some reason it cannot find resources in the assembly. But I don't understand why.
似乎由于某种原因它在程序集中找不到资源。但我不明白为什么。
回答by punker76
from the wiki
来自维基
'Colours' -> 'Colors'
Yes, we changed all
ColourstoColors! The naming of the colors were inconsistent so we decided to change the naming. Also the resource dictionary goes fromColours.xamltoColors.xaml.
“颜色”->“颜色”
是的,我们都改成
Colours了Colors!颜色的命名不一致,所以我们决定改变命名。资源字典也从Colours.xaml到Colors.xaml。
release notes for 0.11.0
0.11.0 的发行说明
Quick How To
快速操作
Application
应用
<Application x:Class="WpfApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
MainWindow
主窗口
<controls:MetroWindow x:Class="WpfApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
Title="MainWindow"
Height="600"
Width="800">
<Grid>
<!-- now your content -->
</Grid>
</controls:MetroWindow>

