【问题标题】:MahApps.Metro cannot find resourcesMahApps.Metro 找不到资源
【发布时间】:2013-12-04 22:06:28
【问题描述】:

我正在尝试使用 MahApps.Metro 创建新的 WPF 应用程序。我完全按照快速入门指南 (http://mahapps.com/MahApps.Metro/guides/quick-start.html) 中的说明进行操作:

  • 将 MahApps.Metro 包从 Nuget 添加到项目中。
  • 添加 xmlns 命名空间并将 Window 替换为 MetroWindow。

此时我可以运行应用程序,但窗口是透明的。标题栏文本和按钮可见(按钮没有样式),但背景是透明的。

  • 为 Window 添加合并的字典代码。

之后我在启动时收到异常:

System.IOException
{"Cannot locate resource 'styles/colours.xaml'."}

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

【问题讨论】:

  • 这是一个大胆的但几乎可以肯定你的标题中的错误声明。
  • @Sheridan,我的意思是“对我来说不起作用”。 :) 改了标题...
  • 你需要把Colours.xaml文件放到你根目录下一个名为Styles的文件夹中。
  • @Sheridan 我应该把 Colours.xaml 带到哪里? Nuget 仅将 Mahapps.Metro dll 添加到项目中,没有 .xaml 文件。

标签: c# wpf mahapps.metro


【解决方案1】:

来自wiki

“颜色”->“颜色”

是的,我们将所有 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>

【讨论】:

  • 这真的很有帮助。他们网站上的快速入门手册没有更新。
猜你喜欢
  • 1970-01-01
  • 2015-01-28
  • 2015-05-03
  • 2013-01-03
  • 2014-03-20
  • 2015-04-13
  • 2021-07-06
  • 1970-01-01
  • 2019-04-20
相关资源
最近更新 更多