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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:32:29+00:00 2026-05-31T12:32:29+00:00

My ComboBox : <ComboBox SourceUpdated=MyComboBox_SourceUpdated ItemsSource={Binding …} SelectedValue={Binding Path=SelectedValueMember, NotifyOnSourceUpdated=True} SelectedValuePath=… DisplayMemberPath=… /> And

  • 0

My ComboBox:

<ComboBox
    SourceUpdated="MyComboBox_SourceUpdated"
    ItemsSource="{Binding ...}"
    SelectedValue="{Binding Path=SelectedValueMember, NotifyOnSourceUpdated=True}"
    SelectedValuePath="..."
    DisplayMemberPath="..."
/>

And my SourceUpdated handler:

private void MyComboBox_SourceUpdated(object sender, DataTransferEventArgs args) {
    if (/* user answers no to an 'are you sure?' prompt */) {
        // TODO: revert ComboBox back to original value
    }
}

I’m having difficult reverting the ComboBox back to its original value (in the “TODO” comment of my code above).

The first and most obvious thing I tried was to simply change back the value of the SelectedValueMember of the DataContext, assuming the binding would update the ComboBox:

MyDataContext.SelectedValueMember = original_value;

When I do this, in the debugger I can see that it is indeed updating the SelectedValueMember value, but the ComboBox does not change back – it holds onto the new value.

Any ideas?


AngelWPF’s answer below works and is probably the neatest and clearest way.

I did however, find a non-obvious solution:

private void MyComboBox_SourceUpdated(object sender, DataTransferEventArgs args) {
    if (/* user answers no to an 'are you sure?' prompt */) {
        Dispatcher.BeginInvoke(new Action(() => {
            MyDataContext.SelectedValueMember = original_value;
        }));
    }
}

Just by putting the operation on a second UI thread by means of BeginInvoke, it works! I could be wrong, but my hunch is that to avoid binding update loops, the actions directly in Source/Target Updated handlers are not reacted to by bindings.

  • 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-31T12:32:30+00:00Added an answer on May 31, 2026 at 12:32 pm

    For explicit conditional update of a source in a binding, use the updatesource trigger as Explicit and handle the selection changed event of combobox to perform the sync with the source based on the message box result.

        <StackPanel DataContext="{StaticResource MyObject}">
          <ComboBox ItemsSource="{Binding MyData}" 
                 DisplayMemberPath="Name" 
                 SelectedValuePath="ID"
                 SelectedValue="{Binding Path=MyID,
                                         Mode=TwoWay,
                                         UpdateSourceTrigger=Explicit}"
                 SelectionChanged="ComboBox_SelectionChanged">
          </ComboBox>
          <TextBlock Text="{Binding Path=MyID}"/>
        </StackPanel>
    

    So the ComboBox is bound to a collection of items (called MyData) having Name and ID as properties. The selected value of the ComboBox is bound to another property called MyID. Now notcie that UpdateSourceTrigger=Explicit in the SelectedValue binding.

    The way I sync the MyID when the selection changes, with the selected value of the combobox ONLY if user selects Yes on a message box as below…

        private void ComboBox_SelectionChanged
          (object sender, SelectionChangedEventArgs e)
        {
            var bndExp
                = BindingOperations.GetBindingExpression(
                    (ComboBox) sender, Selector.SelectedValueProperty);
            if (bndExp != null && bndExp.ParentBinding != null)
            {
                if (MessageBox.Show(
                      "Are you sure?",
                      "Sure?",
                      MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    ((MyObject) bndExp.DataItem).MyID
                        = (int)((ComboBox) sender).SelectedValue;
                }
            }
        }
    

    Thsi way there is no need to revert. The source updates explicitly and you have all the control over it.

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

Sidebar

Related Questions

I have a combobox and set the itemssource to a list of strings: private
I want my WPF ComboBox's ItemsSource property to be bound to MyListObject's MyList property.
I have a ComboBox that uses a DataTemplate . The DataTemplate contains a binding
Say I have a ComboBox , like so: <ComboBox IsEditable=True Height=30> <ComboBoxItem>robot</ComboBoxItem> <ComboBoxItem>Robot</ComboBoxItem> </ComboBox>
I have a ComboBox, whose ItemsSource is bound to a new (not default) ListCollectionView,
I've bound my ComboBox SelectedValue to a string in my codebehind, but when the
I am binding a combobox selected index to an integer value (Mode) in my
I have a ComboBox that has its ItemsSource bound to a static List<CustomSettings> of
I use ComboBox.ItemsSource=[some data collection] to bind data to the control. I want to
A ComboBox within a Form (modal dialog) does not open when clicked, however an

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.