Question

I'm now starting to play with the MahApps.Metro UI toolkit. But I get the first issue :(

The type or namespace name 'Controls' does not exist in the namespace 'Demo.MahApps.Metro'

My MainWindow.xaml is:

<controls:MetroWindow x:Class="Demo.MahApps.Metro.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/Colors.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>

<Grid>

</Grid>

And his Code Behind:

namespace Demo.MahApps.Metro
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

I already installed the prerelease package:

enter image description here

Concrettly I get the issue in the autogenerated MainWindow.g.cs in this line:

public partial class MainWindow : MahApps.Metro.Controls.MetroWindow, System.Windows.Markup.IComponentConnector {

I tried to put MetroWindow in the Code Behind, but doesn't work.

public partial class MainWindow : MetroWindow
{
    ...
}

Thanks for all and greetings!

Was it helpful?

Solution

It seems that your application namespace hides MahApps.Metro namespace. So try to change your namespace to something doesn't contain MahApps.Metro :

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

And your XAML :

<controls:MetroWindow x:Class="Demo.MainWindow"
        .........
        .........>

Create a new project and use different namespace is a safer and cleaner option than rename your existing project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top