我正在尝试使用MahApps.Metro创建新的WPF应用程序。我完全按照快速入门指南(http://mahapps.com/MahApps.Metro/guides/quick-start.html)中所述进行操作:
至此,我可以运行该应用程序了,但是窗口是透明的。标题栏文本和按钮可见(并且按钮没有样式),但是背景是透明的。
之后,我在启动时收到异常消息:
System.IOException
{"Cannot locate resource 'styles/colours.xaml'."}
由于某种原因,它似乎无法在程序集中找到资源。但是我不明白为什么。
最佳答案
<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>
关于c# - MahApps.Metro找不到资源,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20324912/