WPF Check box: Check changed handling

后端 未结 6 897
忘掉有多难
忘掉有多难 2020-12-01 13:33

In WPF data binding, I can bind the IsChecked property to some data, e.g. user setting, but I need to handle \"CheckChanged\" event, I know I can seperately handle <

6条回答
  •  星月不相逢
    2020-12-01 14:07

    Im putting this in an answer because it's too long for a comment:

    If you need the VM to be aware when the CheckBox is changed, you should really bind the CheckBox to the VM, and not a static value:

    public class ViewModel
    {
        private bool _caseSensitive;
        public bool CaseSensitive
        {
            get { return _caseSensitive; }
            set
            {
                _caseSensitive = value;
                NotifyPropertyChange(() => CaseSensitive);
    
                Settings.Default.bSearchCaseSensitive = value;
            }
        }
    }
    

    XAML:

    
    

提交回复
热议问题