简体   繁体   English

MahApps.Metro无法找到资源

[英]MahApps.Metro cannot find resources

I am trying to create new WPF application usign MahApps.Metro. 我正在尝试使用MahApps.Metro创建新的WPF应用程序。 I do exactly as described in quick start guide ( http://mahapps.com/MahApps.Metro/guides/quick-start.html ): 我完全按照快速入门指南( http://mahapps.com/MahApps.Metro/guides/quick-start.html )中的描述进行操作:

  • Add MahApps.Metro package from Nuget to the project. 将Nuget的MahApps.Metro包添加到项目中。
  • Add xmlns namespace and replaced Window with MetroWindow. 添加xmlns命名空间并用MetroWindow替换Window。

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. 但我不明白为什么。

from the wiki 来自维基

'Colours' -> 'Colors' '颜色' - >'颜色'

Yes, we changed all Colours to Colors ! 是的,我们将所有Colours改为Colors The naming of the colors were inconsistent so we decided to change the naming. 颜色的命名不一致,所以我们决定更改命名。 Also the resource dictionary goes from Colours.xaml to Colors.xaml . 资源字典也从Colours.xamlColors.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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM