简体   繁体   English

c#WPF'名称xxx在名称空间中不存在-我缺少什么?

[英]c# WPF 'The name xxx does not exist in the namespace - what am i missing?

I am trying to learn WPF, and specifically, understand data-binding. 我正在尝试学习WPF,尤其是了解数据绑定。 I have started to run through some examples online. 我已经开始在线浏览一些示例。 I cannot get this one to work. 我不能让这个工作。 I have created a Simple Person object as follows and it is in the correct namespace. 我创建了一个Simple Person对象,如下所示,它位于正确的名称空间中。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    namespace SimpleDataBinding
    {
        public class Person
        {
            private string name;
            public Person()
            {
            }
            public Person(string value)
            {
                this.name = value;
            }
            public string PersonName
            {
                get { return name; }
                set { name = value; }
            }
        }
    }

I have created an object of this type. 我已经创建了这种类型的对象。

namespace SimpleDataBinding
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Person Person = new Person();
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
        }
    }
}

and the XAML is as follows - the last line shows the line that it fails on. XAML如下所示-最后一行显示失败所在的行。

<Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:src="clr-namespace:SimpleDataBinding"
  SizeToContent="WidthAndHeight"
  Title="Simple Data Binding Sample">

    <Window.Resources>
        <src:Person x:Key="myDataSource" PersonName="Joe"/>

The error from the build is. 来自构建的错误是。

Severity Code Description Project File Line Suppression State Error The name "Person" does not exist in the namespace "clr-namespace:SimpleDataBinding". 严重性代码说明项目文件行抑制状态错误名称空间“ clr-namespace:SimpleDataBinding”中不存在名称“ Person”。 SimpleDataBinding ...\\repos\\SimpleDataBinding\\SimpleDataBinding\\MainWindow.xaml SimpleDataBinding ... \\ repos \\ SimpleDataBinding \\ SimpleDataBinding \\ MainWindow.xaml

But, Person does exist, and is in the shared namespace. 但是,Person确实存在,并且位于共享名称空间中。 Looking around here at similar issues all i get are recommendations to rebuild, or clean and rebuild - none of which seem to help anyone (or me). 在这里环顾四周,我得到的所有类似问题都是有关重建,清理和重建的建议,但这些建议似乎都没有帮助任何人(或我)。

As i'm new to this, it's likely, i just don't understand something and it's super-frustrating as i should surely be able to get this to work! 由于这是我的新手,很可能是,我只是不了解某些东西,而且它非常令人沮丧,因为我当然应该能够使它工作!

I've pushed the project to github here if it helps anyone... 我推项目的GitHub 这里 ,如果它可以帮助任何人...

You appear to be missing the x:Class directive on your window definition. 您似乎在窗口定义上缺少x:Class指令。 Update your window element in the XAML: 在XAML中更新您的window元素:

<Window
    x:Class="SimpleDataBinding.MainWindow"
    ....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#WPF-名称“…”在命名空间“ clr-namespace:…”中不存在 - C# WPF - The name “…” does not exist in the namespace “clr-namespace:…” 标记名称“ xxx”在xml名称空间clr-namespace中不存在。 无法发布WPF可视C#项目 - The tag “xxx” does not exist in xml namespace clr-namespace. Not able to Publish WPF visual c# project WPF:C#:名称“ Interaction或eventtrigger或contolstroyboardaction”在名称空间“”中不存在 - WPF:C#: The name “Interaction or eventtrigger or contolstroyboardaction” does not exist in the namespace “ ” C#-名称空间“ Windows”中不存在类型或名称空间名称“ Security”(您是否缺少程序集引用?) - C# - The type or namespace name 'Security' does not exist in the namespace 'Windows' (are you missing an assembly reference?) CS0234 C#类型或名称空间名称&#39;Slydeextender&#39;在名称空间中不存在(您是否缺少程序集引用?) - CS0234 C# The type or namespace name 'Slydeextender' does not exist in the namespace (are you missing an assembly reference?) C#类型或名称空间名称“ Interop”在名称空间“ Microsoft.Office”中不存在(您是否缺少程序集引用?) - C# The type or namespace name 'Interop' does not exist in the namespace 'Microsoft.Office' (are you missing an assembly reference?) 名称空间中不存在名称 xxx DataProvider - The name xxx DataProvider does not exist in the namespace C# WPF 在命名空间“clr-namespace=local”中不存在 - C# WPF does not exist in the namespace “clr-namespace=local” C#/WPF:这个回调我错过了什么? - C#/WPF: What am i missing with this callback? c#错误名称空间中不存在类型或名称空间名称&#39;SampleMain&#39; - c# error The type or namespace name 'SampleMain' does not exist in the namespace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM