Mahapps.Metro :在 MetroWindow 类型中找不到可附加属性 WindowCommand
本文关键字:属性 WindowCommand 找不到 Metro MetroWindow 类型 Mahapps | 更新日期: 2023-09-27 18:36:20
我以为我会使用Mahapps.Metro尝试一些WPF Metro,但遇到了错误:
在 MetroWindow 类型中找不到可附加属性 WindowCommand。
我已经包含了来自 nuget 的包,并具有以下 xaml:
<Controls:MetroWindow x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.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>
</Window.Resources>
<Controls:MetroWindow.WindowCommands>
<Controls:WindowCommands>
<Button Content="settings" />
</Controls:WindowCommands>
</Controls:MetroWindow.WindowCommands>
<Controls:MetroContentControl>
<Button Content="Blah" Height="20" Width="150" />
</Controls:MetroContentControl>
</Controls:MetroWindow>
和背后的代码:
using MahApps.Metro.Controls;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : MetroWindow
{
public MainWindow()
{
InitializeComponent();
}
}
}
我正在尝试获取类似于此处文档中的标题栏。
有什么想法吗?
该代码运行良好,您只是拼写错误。更改它:
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
通过:
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
构建你的项目。
您的代码似乎没问题。添加引用后,您似乎尚未构建项目。此错误是否仍然存在?