Cancel combobox selection in WPF with MVVM

后端 未结 12 1471
你的背包
你的背包 2020-12-08 10:23

I\'ve got a combobox in my WPF application:



        
12条回答
  •  温柔的废话
    2020-12-08 11:00

    --Xaml

     
    

    --ViewModel

    private object _SelectedItem;
    public object SelectedItem 
    {
        get { return _SelectedItem;}
        set {
               if(_SelectedItem == value)// avoid rechecking cause prompt msg
                { 
                   return;
                } 
                MessageBoxResult result = MessageBox.Show
                        ("Continue change?", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    ComboBox combo = (ComboBox)sender;
                    handleSelection = false;
                    combo.SelectedItem = e.RemovedItems[0];
                    return;
                }
                _SelectedItem = value;
                RaisePropertyChanged(); 
            }
    }
    

提交回复
热议问题