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

  • Home
  • SEARCH
  • 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 8381239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:39:10+00:00 2026-06-09T16:39:10+00:00

I am figuring out binding in WPF, and running into an issue with object

  • 0

I am figuring out binding in WPF, and running into an issue with object binding.

I have a combobox with an itemsource set to a list of Users

ICollection<User> users = User.GetAll();
cmbContacts.ItemsSource = users;      

I also have an object in my UI which holds the selected user.

public partial class MainWindow : Window
{

    private User selectedUser = new User();

    public MainWindow()
    {
        InitializeComponent();
        ReloadContents();

        Binding b = new Binding();
        b.Source = selectedUser;
        b.Path = new PropertyPath("uFirstName");
        this.txtFirstName.SetBinding(TextBox.TextProperty, b);
   }

And in my combobox’s SelectChanged method…

selectedUser = (User)e.AddedItems[0];

However, the textbox is not updating! I can verify that my binding works by moving the binding code to the combobox SelectChanged methods

selectedUser = (User)e.AddedItems[0];    
Binding b = new Binding();
b.Source = selectedUser;
b.Path = new PropertyPath("uFirstName");
this.txtFirstName.SetBinding(TextBox.TextProperty, b);

Now the textbox updates fine. This seems like the incorrect way of doing things. Can anyone point me in the right direction?

  • 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-06-09T16:39:11+00:00Added an answer on June 9, 2026 at 4:39 pm

    In your code I see one bug – when you set field selectedUser you don’t notify that this data has been changed. Your sample should looks like this:

    public partial class MainWindow : Window, INotifyPropertyChanged
    { 
        private User selectedUser;
    
        public User SelectedUser 
        {
           get 
           {
               return selectedUser;
           }
           set
           {
               selectedUser = value;
               NotifyPropertyChanged("SelectedUser");
           }
        }
    
        public MainWindow() 
        { 
            InitializeComponent(); 
            ReloadContents(); 
    
            // Now the source is the current object (Window), which implements
            // INotifyPropertyChanged and can tell to WPF infrastracture when 
            // SelectedUser property will change value
            Binding b = new Binding(); 
            b.Source = this; 
            b.Path = new PropertyPath("SelectedUser.uFirstName"); 
            this.txtFirstName.SetBinding(TextBox.TextProperty, b); 
       } 
    
       public event PropertyChangedEventHandler PropertyChanged;
    
       private void NotifyPropertyChanged(string info)
       {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
       }
    }
    

    And don’t forget that now you will need to set new value to the property, don’t use field, so the SelectChanged should looks like:

    SelectedUser = (User)e.AddedItems[0]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've having trouble figuring out how to select based on a list in a
I have trouble figuring out why a simple division like this one always returns
I'm having trouble figuring out how to delete a set of records when a
I'm having trouble figuring out a way to unit test a WPF style selector.
I'm rather new to Ruby, and so far, figuring out how to use binding
I'm having a heck of a time figuring this out. I have a WCF
I am having trouble figuring out how to get Facebook insights into from my
I need help in figuring out the solution for my problem. 1. I have
I'm having trouble figuring out how to get the testing framework set up and
I'm having trouble figuring out how to access a cookie from a compiled object.

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.