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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:47:20+00:00 2026-05-26T06:47:20+00:00

I am trying to bind a combobox in WPF like this, <ComboBox Width=350 Margin=5

  • 0

I am trying to bind a combobox in WPF like this,

<ComboBox Width="350" Margin="5" IsEditable="True" ItemsSource="{Binding ComboboxItems}" DisplayMemberPath="Name">

public List<ExpandoObject> ComboboxItems
{
    get
    {
        return comboboxItems;
    }
}

If I set the list like this in my view model,

comboboxItems.Clear();

foreach (ExpandoObject comboboxItem in repository.LoadComboboxItems())
{
    comboboxItems.Add(comboboxItem);
}

NotifyPropertyChanged(this, x => x.ComboboxItems);

The NotifyPropertyChanged seems to work because a breakpoint on the ComboboxItems is hit, but then the combobox list does not update on the GUI. Snoop shows no binding errors or anything like that.

The first time the above list is updated it seems to work, so it can’t be anything to do with using an ExpandoObject I don’t think.

UPDATE:

Using an observable collection works, but I would like to know if I have a setter in a viewmodel like this which binds to a control on the GUI,

public string Database
{
    get
    {
        return importData.Database;
    }
    set
    {
        importData.Database = value;
        NotifyPropertyChanged(this, x => x.Database);

        comboboxItems.Clear();

        foreach (ExpandoObject comboboxItem in repository.LoadComboboxItems())
        {
            comboboxItems.Add(comboboxItem);
        }

        NotifyPropertyChanged(this, x => x.ComboboxItems);
   }
}

Is that setter being run on a background thread? The reason I ask is will the setter block the GUI if it takes a while to load the items from the database?

This is where I went wrong the first time trying to use an ObservableCollection, by running the code in the setter on a background thread using BackgroundWorker. Updating the ObservableCollection caused an exception under those conditions.

  • 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-26T06:47:20+00:00Added an answer on May 26, 2026 at 6:47 am

    I think it will work if you use an ObservableCollection<> instead of a List<>. Unless you use an ObservableCollection, xaml will not know that the contents of the list changed.

    To answer the second part of your question, if you’re trying to set the ObservableCollection using a BackgroundWorker directly, you will get an exception. One of the ways to get around the exception is to set the ObservableCollection using BeginInvoke

    One thing to note: you don’t need to call NotifyPropertyChanged(this, x => x.ComboboxItems); in your setter. This is because the property isn’t changing; the property is a collection and the collection contents are changing. ObservableCollection will notify subscribers that the contents have changed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to troubleshoot my ComboBox. It's declared like this: <ComboBox x:Name=SampleComboBox ItemsSource={Binding Path=SelectedSample.SampleName}
I'm trying to bind a list of custom objects to a WPF Image like
I'm trying to bind to a collection of controls I generate dynamically: <ItemsControl ItemsSource={Binding
I'm trying to databind an object's property to a ComboBox's (editable=true) text property. This
I'm trying to bind column visibility to that of another element like this: <Window
I am trying to bind a generic list like List Parents to a ComboBox.
I'm trying to bind a XAML ComboBox so that its list items are the
Trying to determine if it is possible to bind the SelectedValue of a ComboBox
I'm trying to bind controls in a WPF form to an interface and I
I'm trying to bind a list of integers into an SQLTemplate IN clause like

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.