I've read the online document about data binding but still couldn't make it work. I simply want to understand data binding and do things the way it should.
Here is my code in my UI.xaml.cs
namespace mynamespace
{
class Customer
{
private string _name = "TEST";
public string Name
{
get { return this._name; }
set { this._name = value; }
}
}
public partial class UI: UserControl
{
public UI()
{
InitializeComponent();
Customer c = new Customer();
this.DataContext = c;
}
}
}
The binding code (target is a textbox) looks like this:
<TextBox Name="MyTextBox" Text="{Binding Path=Name}" />
I expect the textbox will show TEST, but it doesn't. There is nothing in the textbox. The documentation (Data Binding Overview, Binding Declarations Overview, and Binding Sources Overview) is not very clear to me.
This is the error message from the Output window:
BindingExpression path error: 'Name' property not found on 'object' ''ConfigurationSettings' (HashCode=36012562)'. BindingExpression:Path=Name; DataItem='ConfigurationSettings' (HashCode=36012562); target element is 'TextBox' (Name='MyTextBox'); target property is 'Text' (type 'String')