Undoing Selection Change in MVVM

3 posts, 1 answers
  1. Masoud
    Masoud avatar
    61 posts
    Member since:
    Aug 2011

    Posted 25 Nov 2011 Link to this post

    Hi,

    I have a RadCombo in a view that in bound to a ViewModel.  SelectedValue of RadCombo is bound to a property Selected with a backing field. Under certain circumstances I need to "reject" user changes to the selection.  In order to achieve this I did the following

    private TL _selected;
     
    public TL Selected
    {
        get { return _selected; }
        set
        {
            if (<some condition -> don't change selection>)
            {
                RaisePropertyChanged("Selected");
                return;
            }
            _selected = value;
            RaisePropertyChanged("Selected");
        }
    }

    However the RadCombo still shows the "rejected" value instead.

    I am running Version 2011.3.1116.1040.

    Thank you for your help!





  2. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 28 Nov 2011 Link to this post

    Hi Klaus,

    As far as I know, while a dependency property is changing, it does not listen to INotifyPropertyChanged notifications. The standard WPF ComboBox control behaves in the same way. To workaround this you should call OnPropertyChanged through a dispatcher. You can find attached a sample application that demonstrates how.

    Regards,
    Valeri Hristov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. Masoud
    Masoud avatar
    61 posts
    Member since:
    Aug 2011

    Posted 28 Nov 2011 Link to this post

    Hi Valeri,

    thank you for your reply!

    I have implementied your solution and it works fine!

    Regards
Back to Top