tags:

views:

44

answers:

1

Hi,

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 binded. Any one correct the error plz. Thanks,

+4  A: 

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)

  • Properties
  • Accessors (public, private, protected, internal) - you cant bind to a non public property
  • INotifyPropertyChanged

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;
....
Aran Mulholland
+1 good answer, saved me having to write anything - i just hope @jjjou bothers to mark it.
slugster
+1, although I'm surprised to see that Sigfried is the Dutch version of "Roy" :)
DanM
these dutch translations get the uninitiated every time :) I'm betting he wont mark it tho....sigh
Aran Mulholland