简体   繁体   中英

Mahapps.Metro : The attachable property WindowCommands was not found in type MetroWindow

I thought i'd try out some WPF Metro using Mahapps.Metro and have come across the error:

The attachable property WindowCommands was not found in type MetroWindow

I have included the packages from nuget and have the following 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>

and the code behind:

using MahApps.Metro.Controls;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : MetroWindow 
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

I am attempting to get the title bar like the one on the documentation here .

Any ideas?

That code works well, you just did a little misspelling. Change that:
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
by that:
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />

Build your project.

Your code seems OK. It seems you might have not build your project after the references were added. Does this error still persist?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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