Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
755
Cancel a new selected value in a XamComboeditor
posted

Hi,

I have a question about cancelling a userinteraction on a XamComboEditor.

This is the scenario:
The user selects a new value which is available in the list.
The user gets a Dialog if he really want to make that change.

If the user anwsers yes then I don't have to do a thing. The underlying property is set to the new value and everything is OK.
If the user awnsers No then I won't set the underlying databinded property, but the combo shows me that the new value is the value the user selected before he said no. In other words the value property isn't in sync anymore with the selected item property.

WHat am I doing wrong ?

Parents
No Data
Reply
  • 69686
    Suggested Answer
    posted

    Hello,

    You can try the following code snippet, where chaged is a boolean variable. It is necessary, because if you choose to revert the value back to the old one, ValuChanged will fire again just for this - to update to the old one, so you need to cancel that second invocation:

    void xamComboEditor1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)

            {

                Debug.WriteLine("value changed");

                if (changed)

                {

                    changed = false;

                    return;

                }

                if (MessageBox.Show("Confirm?", "MS BOX", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes, MessageBoxOptions.DefaultDesktopOnly)

                    == MessageBoxResult.Yes)

                {

                    xamComboEditor1.EndEditMode(true, true);

                }

                else

                {

                    xamComboEditor1.EndEditMode(false, true);

                    changed = true;

                }

            }

Children