The name ViewModel does not exist in the namespace “clr-namespace:Project.ViewModels”

前端 未结 18 1735
旧时难觅i
旧时难觅i 2020-12-04 23:55

Now that\'s a real strange error. I am working on a WPF application and following MVVM. In my MainWindow I am setting views and view models and I get this strange error. Alt

相关标签:
18条回答
  • 2020-12-05 00:31

    I ran into this and had trouble working through it based on the answers posted in this forum. I had renamed my project at some point and had introduced a typo into the auto-generated AssemblyInfo.cs file (in the assembly: AssemblyTitle and assembly: AssemblyProduct fields). Surprisingly, this was the only compilation error that I got as a result. Just something a bit non-obvious to double-check if you're getting this error and the previous suggestions don't work.

    0 讨论(0)
  • 2020-12-05 00:33

    I think how I ran into this was to create the View first, and pointed to a ViewModel that didnt exist. Afterwards I create the ViewModel. Kept getting error, could not find ViewModel.

    Finally I noticed that the path of newly created View page was pointing to bin directory instead of Views directory. So, I left ViewModel alone. Deleted and recreated View again. Right Clicked and Cleaned the Project, closed all files opened within Solution, and Rebuilt. That finally fixed it.

    0 讨论(0)
  • 2020-12-05 00:34

    I had the same problem. I had the right namespace, the right class name, and I even updated the PATH. Finally, I took out the "DataType" from the XAML, got it to compile, the added the DataType back in and it worked. Seems like it was a chicken and egg problem. The XAML doesn't see it until it has been compiled in, and you can't compile with it in the DataType. So, create the MV first, and compile it. Then, add to XAML.

    0 讨论(0)
  • 2020-12-05 00:34

    For us it was simply that the Dll Project was set to Platform Target x64 in Visual Studio 2013. After setting it to Any. Everything starts working again.

    0 讨论(0)
  • 2020-12-05 00:35

    In my case implementation of IValueConverter was the problem

    I have changed:

    public object Convert(object value, 
      Type targetType, 
      object parameter, 
      string language) 
    { //code }
    

    to

    public object Convert(object value, 
      Type targetType, 
      object parameter, 
      System.Globalization.CultureInfo culture) 
    { //code } 
    

    ...rebuild project

    0 讨论(0)
  • 2020-12-05 00:37

    Rebuild your solution (sometimes clean then build works better). Then look at your error list, scroll to the very bottom, and it will most likely indicate an error that is not allowing your assembly to compile, and the XAML compiler is most likely using a cached version of the assembly, not the new one you mean to build.

    0 讨论(0)
提交回复
热议问题