【问题标题】:The name ' ' does not exist in the namespace ' '名称空间“ ”中不存在名称“ ”
【发布时间】:2017-11-01 10:55:34
【问题描述】:

从头开始接触 MVVM,我遇到了以下令人沮丧的错误:

命名空间中不存在名称“MainWindowViewModel” “clr-命名空间:Data_version_3.ViewModels.MainWindowViewModel”。

但是项目构建并运行,我只是看不到能够对设计进行修改的窗口,因为它提示存在错误。

突出的 XAML 是:

<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>

还有我的视图模型:

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);
        }

看过很多关于这个的帖子,包括:

The name does not exist in the namespace error in XAML

但不幸的是,这并没有奏效。尝试过清理和重建、关闭和打开等。所有 IT 的最爱,但无济于事,所以我猜这是我想念的东西。任何帮助表示赞赏。

编辑 - 以防万一它有任何相关性,我使用的是 VS 2015

【问题讨论】:

  • 嗯...也许你的命名空间中的下划线是原因。试试没有。这只是一个猜测。
  • 两个类是否在同一个程序集/项目中?
  • @Lennart MainWindow 类和 MainWindowViewModel?是的,MainWindow 在后面的代码中,但这会导致问题吗?
  • 所以这是您的 WPF 设计器窗口中的 IntelliSense 错误?不幸的是,这种情况有时会发生。实际上有一个名为XDesProc.exe 的后台进程会持续编译您的项目并将数据反馈到Visual Studio。您有几个选择:1)忽略它,2)全部重建,3)重新启动 Visual Studio(或杀死 XDesProc.exe)。如果最后一个选项不起作用,则必须返回 1)。
  • 为什么你的视图模型继承自命令?您是否也尝试过在不参考您的 VM 的情况下构建它。建好后再添加?

标签: c# wpf xaml mvvm


【解决方案1】:

在我的情况下,这个问题是项目和解决方案中有空格,而代码中的命名空间有下划线。重命名项目和解决方案,使其与代码匹配,在清理和构建之后,解决了问题。

【讨论】:

    猜你喜欢
    • 2016-11-06
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 2012-12-06
    • 2016-11-29
    • 1970-01-01
    相关资源
    最近更新 更多