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 5948055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:03:09+00:00 2026-05-22T17:03:09+00:00

I have a combobox which binds to a collection of Foo on my viewmodel

  • 0

I have a combobox which binds to a collection of Foo on my viewmodel (FooCollection). I also set the SelectedItem property of the combobox to a property on my viewmodel of type Foo called SelectedFoo

I then set FooCollection and SelectedFoo and fire the appropriate OnPropertyChanged events.

My combobox contains the list of Foo, but the item displayed in the combobox is always the first item in the list. However, if you drop down the combobox, the item that is then highlighted is the correct item (SelectedFoo). Therefore, it is selecting the correct item, but not displaying it.

<ComboBox Grid.Row="5"  ItemsSource="{Binding Path=FooCollection}" 
                         SelectedItem="{Binding SelectedFoo, Mode=TwoWay}" 
                         Name="FooSelectionControl"/>

Does anyone know how to fix this?

  • 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-22T17:03:10+00:00Added an answer on May 22, 2026 at 5:03 pm

    Hmm, it works on my end. What kind of collection are you using?

    Screenshot 1

    Screenshot 2

        <ComboBox 
            SelectedItem="{Binding SelectedFoo, Mode=TwoWay}"
            ItemsSource="{Binding FooCollection}">
        </ComboBox>
    

    Code behind:

        public MainWindow()
        {
            InitializeComponent();
    
            DataContext = this;
    
            FooCollection = new BindingList<Foo>();
    
            var foo = new Foo("Alpha");
            FooCollection.Add(foo);
    
            foo = new Foo("Beta");
            SelectedFoo = foo;
            FooCollection.Add(foo);
    
            foo = new Foo("Gamma");
            FooCollection.Add(foo);
        }
    
        public Foo SelectedFoo
        {
            get { return (Foo)GetValue(SelectedFooProperty); }
            set { SetValue(SelectedFooProperty, value); }
        }
        public static readonly DependencyProperty SelectedFooProperty =
            DependencyProperty.Register("SelectedFoo", typeof(Foo), typeof(MainWindow), new UIPropertyMetadata(null));
    
        public BindingList<Foo> FooCollection
        {
            get { return (BindingList<Foo>)GetValue(FooCollectionProperty); }
            set { SetValue(FooCollectionProperty, value); }
        }
        public static readonly DependencyProperty FooCollectionProperty =
            DependencyProperty.Register("FooCollection", typeof(BindingList<Foo>), typeof(MainWindow), new UIPropertyMetadata(new BindingList<Foo>()));
    

    and class Foo,

    public class Foo : INotifyPropertyChanged
    {
        public Foo(string name)
        {
            _name = name;
        }
    
        private string _name;
    
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name == value) return;
    
                _name = value;
                OnPropertyChanged("Name");
            }
        }
    
        public override string ToString()
        {
            return Name;
        }
    
        #region INotifyPropertyChanged event
    
        ///<summary>
        ///Occurs when a property value changes.
        ///</summary>
        public event PropertyChangedEventHandler PropertyChanged;
    
    
        /// <summary>
        /// Raises the <see cref="PropertyChanged"/> event for
        /// a given property.
        /// </summary>
        /// <param name="propertyName">The name of the changed property.</param>
        protected void OnPropertyChanged(string propertyName)
        {
            //validate the property name in debug builds
            VerifyProperty(propertyName);
    
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    
    
        /// <summary>
        /// Verifies whether the current class provides a property with a given
        /// name. This method is only invoked in debug builds, and results in
        /// a runtime exception if the <see cref="OnPropertyChanged"/> method
        /// is being invoked with an invalid property name. This may happen if
        /// a property's name was changed but not the parameter of the property's
        /// invocation of <see cref="OnPropertyChanged"/>.
        /// </summary>
        /// <param name="propertyName">The name of the changed property.</param>
        [Conditional("DEBUG")]
        private void VerifyProperty(string propertyName)
        {
            Type type = GetType();
    
            //look for a *public* property with the specified name
            PropertyInfo pi = type.GetProperty(propertyName);
            if (pi == null)
            {
                //there is no matching property - notify the developer
                string msg = "OnPropertyChanged was invoked with invalid property name {0}: ";
                msg += "{0} is not a public property of {1}.";
                msg = String.Format(msg, propertyName, type.FullName);
                Debug.Fail(msg);
            }
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

well, I have a combobox which I have bind his selectedItem property to a
I have the following collection which i would like to bind to a combobox:
I have a very simple WPF application which displays a ComboBox which binds to
I have a combobox which binds data from the database. It gets the data
I have ComboBox which is data bounded to a collection. I have customized the
i have a combobox which is displaying date from database...in my database the date
I have a combobox which is populated by the Keys enumeration (winforms). The problem
I have a combobox from which i need to programmatically disable items depending on
I have a datagridview and a combobox which get populated randomly with data. However,
I have a simple UserControl containing a ComboBox which is empty at first. The

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.