-1

New to MVVM from scratch, and I am hitting the frustrating error of:

The name "MainWindowViewModel" does not exist in the namespace "clr-namespace:Data_version_3.ViewModels.MainWindowViewModel".

But the project builds, and works, I just cannot see the window to be able to make amendments to the design, as it advises there is an error.

The salient XAML is:

<Window x:Class="Data_version_3.MainWindow"  
        WindowStartupLocation="CenterScreen"     
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" 
        dx:ThemeManager.Theme="Office2010Black" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"       
        xmlns:vm="clr-namespace:Data_version_3.ViewModels.MainWindowViewModel"
        mc:Ignorable="d"       
        Title="GG Data import tool" 
        WindowState ="Maximized"
        Icon="./Images/GG.ico"
        KeyDown="OnButtonKeyDown">
    <Window.DataContext>
        <vm:MainWindowViewModel/>
    </Window.DataContext>

And my view model:

namespace Data_version_3.ViewModels.MainWindowViewModel
{
    public class MainWindowViewModel:RelayCommand
    {
        Web w = null;
        public Excel ex = null;
        public Report rp = null;
        public Helpers he = null;
        SQLThings.Data da = null;
        public Logging lg = new Logging();

        public MainWindowViewModel()
        {
            he = new Helpers(this);
            w = new Web(this);
            ex = new Excel(this);
            da = new SQLThings.Data(this);
            rp = new Report(this);
        }

Have seen a number of posts about this, including:

The name does not exist in the namespace error in XAML

But unfortunately this has not worked. Have tried cleans and rebuilds, closing and opening etc. All the IT favourites, to no avail, so I am guessing it is something I am missing. Any help appreciated.

Edit - Just in case it has any relevance, I am using VS 2015

Keith
  • 1,008
  • 10
  • 19
  • Hm... maybe the underscore in your namespace is the reason. Try without. It's just a guess. – MrToast Nov 01 '17 at 11:02
  • Are both classes in the same assembly/project? – Lennart Nov 01 '17 at 11:05
  • @Lennart the MainWindow class and MainWindowViewModel? Yes, the MainWindow is in the code behind however, would that cause an issue? – Keith Nov 01 '17 at 11:10
  • 1
    So this is an IntelliSense error in your WPF designer window? Unfortunately, this sometimes happens. There is actually a background process named `XDesProc.exe` that continuously compiles your project and feeds data back into Visual Studio. You have several options: 1) ignore it, 2) rebuild all, 3) restart Visual Studio (or kill `XDesProc.exe`). If the last option doesn't work you have to go back to 1). – Martin Liversage Nov 01 '17 at 11:11
  • @Leonidas199x No, that's fine. If they *would* be in different assemblies, you'd also had to specify the assembly in the namespace declaration. Otherwise there's really not a lot you can do, the XAML preview is kinda funky sometimes. You could try VS 2017 with the newest updates which is supposed to have some improvements for the designer. – Lennart Nov 01 '17 at 11:14
  • @MartinLiversage thanks for the info, didn't know that was the case. Unfortunately I have tried all and it doesn't resolve. Ideally need to see the window to be able to make amendments. – Keith Nov 01 '17 at 11:17
  • 1
    Why your view model inheriting from command? Also have you tried building this without the reference to your VM. And then add it after it has been built? – XAMlMAX Nov 01 '17 at 11:24
  • @ooorndtski You were correct. The issue was that the solution and the project were name 'Data version 3' renaming these to 'Data_version_3' resolved the issue. Thanks for the nudge in the right direction. – Keith Nov 01 '17 at 11:29
  • Glad that i could help. Please create an complete answer and accept it so that the solution to the problem can be found easier – MrToast Nov 01 '17 at 11:36

1 Answers1

1

This issue in my case was that the project, and the solution had spaces in, whilst the namespace in the code had underscores. Renaming the project and solution so they matched the code, after a clean and build, resolved the problem.

Keith
  • 1,008
  • 10
  • 19