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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:05:01+00:00 2026-06-01T20:05:01+00:00

I have a ComboBox whose properties ItemsSource and SelectedValue are bound to a model.

  • 0

I have a ComboBox whose properties ItemsSource and SelectedValue are bound to a model. Sometimes, the model needs to adjust the selected item to a different one, but when I do it in the model, the model value is not being reflected in the View, even though the SelectedValue is properly set (checked both with snoop and in SelectionChanged event handler).

To illustrate the problem, here is a simple xaml:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <Grid>
      <ComboBox Height="25" Width="120" SelectedValue="{Binding SelectedValue}" SelectedValuePath="Key" ItemsSource="{Binding PossibleValues}" DisplayMemberPath="Value"/>
   </Grid>
</Window>

And here is the model:

using System.Collections.Generic;
using System.Windows;
using System.ComponentModel;

namespace WpfApplication1
{
   public partial class MainWindow : Window, INotifyPropertyChanged
   {
      int m_selectedValue = 2;
      Dictionary<int, string> m_possibleValues = new Dictionary<int, string>() { { 1, "one" }, { 2, "two" }, { 3, "three" }, {4,"four"} };

      public int SelectedValue
      {
         get { return m_selectedValue; }
         set 
         {
            if (value == 3)
            {
               m_selectedValue = 1;
            }
            else
            {
               m_selectedValue = value;
            }
            PropertyChanged(this, new PropertyChangedEventArgs("SelectedValue"));
         }
      }
      public Dictionary<int, string> PossibleValues
      {
         get { return m_possibleValues; }
         set { m_possibleValues = value; }
      }


      public MainWindow()
      {
         InitializeComponent();
      }

      public event PropertyChangedEventHandler PropertyChanged;
   }
}

I Expected the behaviour to be as follows:

  1. Initially, two is selected
  2. Select “one” -> ComboBox displays “one”
  3. Select “two” -> ComboBox displays “two”
  4. Select “three” -> ComboBox displays “one“
  5. Select “four” -> ComboBox displays “four”

However, in #4, “three” is displayed. Why? The value in the model was changed to 1 (“one”), but the View still displays 3 (“three”).

I have found a workaround by explicitly updating the binding target in a SelectionChanged event handler, but this seems wrong. Is there another way to achieve 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-06-01T20:05:03+00:00Added an answer on June 1, 2026 at 8:05 pm

    When you select an item, the binding engine will update the model, and will ignore any PropertyChanged for the property it just changed during the time it’s invoking the property setter. If it didn’t, things could potentially go into an infinite loop.

    The system assumes that the setter won’t change the value it was passed. The workaround here is simple: use Dispatcher.BeginInvoke() or set IsAsync=True on your binding to get the behavior you’re looking for. However, I personnaly strongly discourage you to do this. Not only because it introduces a whole bunch of new problems related to timings, but mainly because it’s a workaround to a problem that shouldn’t exist in the first place.

    Simply don’t do this. It’s not only applying to WPF: anything changing a setter could expect that the value it just set was correctly set is no exception is thrown. Changing the value inside the setter is counter intuitive and could bite you later. Plus, it can be really disturbing for the user of your application to see the combobox ignoring its selection.

    If you don’t like the value being passed, throw an exception and use Binding.ValidatesOnExceptions to tell WPF that it’s expected. If you don’t want the user to select this value, don’t put it inside the list in the first place. If the item shouldn’t be available conditionally because of other business rules, filter the list dynamically or apply triggers.

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

Sidebar

Related Questions

I have a ComboBox, whose ItemsSource is bound to a new (not default) ListCollectionView,
I have a ComboBox whose ItemsSource is bound to an ObjectDataProvider that has its
I have a ComboBox with a label function like this one: private function fieldLabelFunction(item:Object):String
I have a datagrid whose itemsSource is bound to a multiconverter which uses a
I have a ComboBox that doesn't seem to update the SelectedItem/SelectedValue. The ComboBox ItemsSource
I've got a simple question, I've got a ComboBox whose ItemsSource is bound to
I have a ComboBox in WPF whose ItemsSource is set to a list programmatically.
I have one combobox on the window form and I have one method which
I have a combobox in Access 2003 whose recordset is obtained from a stored
I have a ComboBox whose xaml is as follows <ComboBox Name=ComboBoxDiscussionType IsEnabled={Binding ElementName=ComboBoxDiscussionType, Path=Items.Count,

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.