我正在學習使用this tutorial的WPF數據綁定。將類實例綁定到控件
這是我的XAML:
Window x:Class="DataBinding_01.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:Person x:Key="PersonDataSource" Name="Joe"/>
</Window.Resources>
<DockPanel Height="Auto" Name="panel" Width="Auto" LastChildFill="True">
<TextBox DockPanel.Dock="Top" Height="23" Name="txtName" Width="Auto" />
<Button Content="Button" Name="button1" Width="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Click="button1_Click" />
</DockPanel>
</Window>
這裏是我的代碼:
public partial class MainWindow : Window
{
Person myPerson = null;
public MainWindow()
{
InitializeComponent();
myPerson = this.Resources["PersonDataSource"] as Person;
myPerson.NameProperty = "hi, again!";
}
}
public class Person
{
Person()
{
NameProperty = "hi";
}
Person(String _name)
{
NameProperty = _name;
}
private String name = "";
public String NameProperty
{
get { return name; }
set
{
name = value;
}
}
}
當我建立的解決方案,我得到的錯誤:
Error 1 ''local' is an undeclared prefix. Line 7, position 10.' XML is not valid. C:\Users\Admin\Desktop\DataBinding_01\DataBinding_01\MainWindow.xaml 7 10 DataBinding_01
爲什麼和如何才能我修復它 ?