Reputation: 11
my XAML is
<TextBox Name="DutchName" HorizontalAlignment="Right" Text="{Binding customer,Path=DutchName }" />
my class is
class customer
{
Name name;
}
class Name
{
string DutchName;
string EnglishName;
}
The TextBox
is not bound.
Can anyone correct this error please?
Thanks,
Upvotes: 1
Views: 200
Reputation: 23935
i dont think your code would compile for starters,
should be
public class customer
{
public Name name { get; set; }
}
public class Name
{
public string DutchName { get; set; }
public string EnglishName { get; set; }
}
this will enable you to get once and set the properties from xaml, however if you set the properties in code you need to implement INotifyPropertyChanged (otherwise your user interface wont know). From your question i think you need to do a little more study. find out about these topics. (to start with)
your xaml binding should look like this
<TextBox HorizontalAlignment="Right" Text="{Binding Path=name.DutchName }" />
if you set the data context of the window/user control you are working in to be the customer. e.g.
....
InitializeComponent();
customer cust = new customer();
cust.Name = new Name { DutchName = "Sigfried", EnglishName = "Roy" };
this.DataContext = cust;
....
Upvotes: 5