我一直在挠头,我确定这是一个显而易见的问题,但我就是看不到它。
我做了一个新的应用程序"WpfApplication3"
我添加一个类"人.cs":
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApplication3
{
public class Person
{
public string Name { get { return "Jonas"; } }
}
}
然后我试试这个:
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication3"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.Resources>
<local:Person x:Key="somePerson"/>
</Grid.Resources>
<!--<TextBlock Text="{Binding {StaticResource somePerson.Name}}"/>-->
</Grid>
</Window>
我收到错误"名称"人"在命名空间"clr-namespace:WpfApplication"中不存在。
我做错了什么?
使用 VS Express 2012 for Windows 桌面(试用版)。
这看起来很奇怪,但我测试过,果然找不到人。
然后我向"人"中添加了一个公共 ctor
public class Person
{
public Person() { }
}
它会编译
现在我可以删除 ctor 并且它(仍然)会编译
尝试(多次)清理和重建
我知道这毫无意义,但它发生在我身上