MahApps.Metro 无法找到资源。

9
我试图使用MahApps.Metro创建新的WPF应用程序。我按照快速入门指南(http://mahapps.com/MahApps.Metro/guides/quick-start.html)中描述的步骤进行操作:
  • 将MahApps.Metro包从Nuget添加到项目中。
  • 添加xmlns命名空间并用MetroWindow替换Window。
此时,我可以运行应用程序,但窗口是透明的。标题栏文本和按钮可见(且未经过样式设置),但背景是透明的。
  • 为窗口添加合并字典代码。
之后,我在启动时收到异常:
System.IOException
{"Cannot locate resource 'styles/colours.xaml'."}

似乎由于某种原因,它无法在程序集中找到资源。但我不明白为什么。

@Sheridan,我应该把Colours.xaml放在哪里?Nuget只向项目添加了Mahapps.Metro dll文件,没有.xaml文件。 - Aleksey Shubin
也许你应该联系那个示例的作者,请求一并提供其他的XAML文件? - Sheridan
我最近一直在使用 MahApps,它工作得非常好。你需要在哪里添加合并字典呢? - har07
再次查看后,似乎这些“Style”文件确实应该包含在dll中。虽然我无法告诉您为什么您没有在下载中获得这些XAML文件,但我能做的就是建议您尝试重新下载所有文件。您链接的页面显示了两种下载方式,所以如果我是您,我会尝试两种方式。 - Sheridan
2
颜色现在变成Colors -> https://github.com/MahApps/MahApps.Metro/wiki/Breaking-Changes-or-WTF-is-happening-with-the-ALPHA-version#colours---colors - punker76
显示剩余7条评论
1个回答

14

来自维基百科

'Colours' -> 'Colors'

是的,我们将所有的Colours改为了Colors!颜色的命名不一致,因此我们决定更改命名。此外,资源字典从Colours.xaml变成了Colors.xaml

0.11.0版发布说明

快速教程

应用程序

<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>

主窗口

<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>

那真的很有帮助。他们网站上的快速入门手册没有更新。 - lena

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接