WPF:名称在命名空间中不存在 [英] WPF: The name does not exist in the namespace

查看:112
本文介绍了WPF:名称在命名空间中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VS2013 构建 C#/WPF 应用程序,并且我有以下类定义(在正在运行的应用程序的同一程序集中):

namespace MyNamespace{公开课 MyKey{公共 MyKey() { }公共字符串名称 = "";}}

在 MainWindow.xaml 中,我有:

<窗口.资源><local:MyKey x:Key="key"/></Window.Resources>...

VS 不断报告

<块引用>

名称空间中不存在名称MyKey""clr-namespace:MyNamespace"

有什么想法吗?

附言我尝试了以下解决方案(来自已在 stackoverflow 中发布的问题),但都没有奏效:

  1. 将类移动到不同的命名空间,然后在 xaml 引用中使用新的命名空间
  2. 重新启动 VS 并清理/重建解决方案
  3. 清理解决方案,然后重命名其文件夹,然后再次构建解决方案
  4. 将引用更改为:

<块引用>

xmlns:local="clr-namespace:MyNamespace;assembly="

附加信息:目标架构:X64,目标框架:.Net 4.5

解决方案

这个已知 VS 错误的一个常见解决方案是更改构建目标平台.

  1. 如果您当前的构建目标平台是 x64,请更改为 x86.如果当前是 x86,请更改为 x64.

  2. 清理和构建新目标平台的解决方案.

  3. 改回所需的目标平台并重新构建.

I am building a C#/WPF application using VS2013, and I have the following class definition (in the same assembly of the running application):

namespace MyNamespace
{
    public class MyKey
    {
        public MyKey() { }
        public string name = "";
    }
}

In MainWindow.xaml I have:

<Window x:Class="MyNamespace.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:MyNamespace"
        Title="MainWindow" Height="350" Width="525" WindowState="Maximized" WindowStyle="None">
    <Window.Resources>
        <local:MyKey x:Key="key" />
    </Window.Resources>
...

VS keeps reporting that

The name "MyKey" does not exist in namespace "clr-namespace:MyNamespace"

Any ideas?

P.S. I tried the following solutions (from already posted questions in stackoverflow) but none of them worked:

  1. Moving the class to a different namespace, then using the new namespace in xaml reference
  2. Restarting VS and cleaning/rebuilding the solution
  3. cleaning the solution then renaming its folder then building the solution again
  4. changing the reference to:

xmlns:local="clr-namespace:MyNamespace;assembly="

Edit: Additional info: The target architecture: X64, target framework: .Net 4.5

解决方案

One common solution to this known VS bug that you haven't specified as having tried is changing the build target platform.

  1. If your current build target platform is x64, change to x86. If it's currently x86, change to x64.

  2. Clean and Build solution for new target platform.

  3. Change back to desired target platform and re-build.

这篇关于WPF:名称在命名空间中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆