[英]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 这里 ,如果它可以帮助任何人...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.