WPF ComboBox Binding

Posted by MadSeb on Stack Overflow See other posts from Stack Overflow or by MadSeb
Published on 2010-03-19T13:54:33Z Indexed on 2010/03/19 14:21 UTC
Read the original article Hit count: 289

Filed under:
|
|

Hi

So I have the following model:

public class Person
{
  public String FirstName { get; set; }
  public String LastName { get; set; } 
  public String Address { get; set; }
  public String EMail { get; set; }
  public String Phone { get; set; } 
}

public class Order
{
   public Person Pers { get; set;}
   public Product Prod { get; set; }
   public List<Person> AllPersons { get; set; } 

   public Order(Person person, Product prod )
   {
     this.Pers = person;
     this.Prod = prod;
     AllPersons = database.Persons.GetAll(); 
   }

}

And I have a WPF window used to edit an order. I set the DataContext to Order.

public SetDisplay(Order ord)
{
 DataContext = ord; 
}

I have the following XAML:

<ComboBox Name="myComboBox"
          SelectedItem = "{Binding Path=Pers, Mode=TwoWay}"
          ItemsSource = "{Binding Path=AllPersons, Mode=OneWay}"
          DisplayMemberPath = "FirstName"
          IsEditable="False" />


<Label Name="lblPersonName" Content = "{Binding Path=Pers.FirstName}" />
<Label Name="lblPersonLastName" Content = "{Binding Path=Pers.LastName}" />
<Label Name="lblPersonEMail" Content = "{Binding Path=Pers.EMail}" />
<Label Name="lblPersonAddress" Content = "{Binding Path=Pers.Address}" />

However, the binding does not seem to work.......When I change the selected item , the labels do not update ....

Regards!!

Any reply is appreciated !!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about combobox