I am studying WPF databinding using this tutorial.
Here is my 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>
Here is my code:
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;
}
}
}
When I am building the solution I get the error:
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
Why and how can I fix it ?
You need to specify the
localnamespace in XAML to point to yourPerson‘s class namespace:If the
Personclass in theDataBinding_01namespace:In your sample article: