Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 678909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:12:05+00:00 2026-05-14T01:12:05+00:00

So I have the following model: public class Person { public String FirstName {

  • 0

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 !!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:12:06+00:00Added an answer on May 14, 2026 at 1:12 am

    Your model will need to fire change notifications. See INotifyPropertyChanged and INotifyCollectionChanged.

    For INotifyPropertyChanged, you could use a base ViewModel class such as this one. For collections, ObservableCollection<T> does the hard work for you. However, in your case your collection won’t change after the UI is bound to it, so you shouldn’t need an observable collection. Regardless, I’d generally recommend using observable collections in your view model layer to save head-scratching should the code ever change.

    An example of what this would look like is:

    public class Person : ViewModel
    {
        private string firstName;
        private string lastName;
        private string email;
        private string phone;
    
        public string FirstName
        {
            get
            {
                return this.firstName;
            }
            set
            {
                if (this.firstName != value)
                {
                    this.firstName = value;
                    OnPropertyChanged(() => this.FirstName);
                }
            }
        }
    
        public string LastName
        {
            get
            {
                return this.lastName;
            }
            set
            {
                if (this.lastName != value)
                {
                    this.lastName = value;
                    OnPropertyChanged(() => this.LastName);
                }
            }
        }
    
        // and so on for other properties
    }
    
    public class Order : ViewModel
    {
        private readonly ICollection<Person> allPersons;
        private Person pers;
        private Product prod;
    
        public Person Pers
        {
            get
            {
                return this.pers;
            }
            set
            {
                if (this.pers != value)
                {
                    this.pers = value;
                    OnPropertyChanged(() => this.Pers);
                }
            }
        }
    
        public Product Prod
        {
            get
            {
                return this.prod;
            }
            set
            {
                if (this.prod != value)
                {
                    this.prod = value;
                    OnPropertyChanged(() => this.Prod);
                }
            }
        }
    
        // no need for setter
        public ICollection<Person> AllPersons
        {
            get
            {
                return this.allPersons;
            }
        }    
    
        public Order(Person person, Product prod )
        {
            this.Pers = person;
            this.Prod = prod;
    
            // no need for INotifyCollectionChanged because the collection won't change after the UI is bound to it
            this.allPersons = database.Persons.GetAll(); 
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Model: public class Person { public string Name {get;set;} public
I have the following model: public class Person { public string Name { get;
I have the following Model: public class DeliveryTracking { public string TrackingRef { get;
I have following model: public class FormularModel { [Required] public string Position { get;
I have the following model public class UserViewModel { public String CVR_Nummer { get;
I have the following model: public class A { public int? Id {get;set;} public
ok say i have the following model: public class bar{ public string bar {get;
I'm using the Code First approach and have the following Model: public class Person
I have the following model, view and controller. Model public class Person { public
I have the following model: public class Tag { public int Id { get;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.