WPF:这个名字没有命名空间中存在 [英] WPF: The name does not exist in the namespace

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

问题描述

我使用VS2013建立一个C#/ WPF应用程序,我有下面的类定义(在运行的应用程序相同的程序集):

 命名空间myNameSpace对象
{
公共类的myKey
{
公众的myKey(){}
公共字符串名称=;
}
}

在MainWindow.xaml我有:



 <窗​​口x:类=MyNamespace.MainWindow
的xmlns =htt​​p://schemas.microsoft.com/winfx / 2006 / XAML /演示
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
的xmlns:地方=CLR的命名空间:myNameSpace对象
标题=主窗口HEIGHT =350WIDTH =525的WindowState =最大化WindowStyle =无>
< Window.Resources>
<局部:的myKey X:键=键/>
< /Window.Resources>
...



VS不断报告说,




的myKey的名字并不在命名空间
存在CLR的命名空间:myNameSpace对象




任何想法?



PS我尝试以下解决方案(从已张贴在计算器的问题),但他们没有工作:




  1. 移动类不同的命名空间,然后使用新的命名空间在XAML参考

  2. 重新启动VS和清洗/重建的解决方案

  3. 清洁液,然后重命名的文件夹,然后再构建解决方案

  4. 改变基准为:




XMLNS:地方= CLR命名空间:myNameSpace对象;装配=




编辑:附加信息:目标架构:X64,目标框架:.NET 4.5


解决方案

本VS错误称为一个共同的解决方案,你有没有指定为具有尝试正在改变构建目标平台。




  1. 如果您当前构建目标平台是64位,更改为86。如果它是当前的x86,更改为64位。


  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天全站免登陆