WPF Databinding CheckBox.IsChecked

后端 未结 4 424
甜味超标
甜味超标 2020-12-18 01:20

How would I bind the IsChecked member of a CheckBox to a member variable in my form?

(I realize I can access it directly, but I am trying to learn about databinding

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-18 01:33

    Addendum to @Will's answer: this is what your DependencyProperty might look like (created using Dr. WPF's snippets):

    #region ShowPending
    
    /// 
    /// ShowPending Dependency Property
    /// 
    public static readonly DependencyProperty ShowPendingProperty =
        DependencyProperty.Register("ShowPending", typeof(bool), typeof(MainViewModel),
            new FrameworkPropertyMetadata((bool)false));
    
    /// 
    /// Gets or sets the ShowPending property. This dependency property 
    /// indicates ....
    /// 
    public bool ShowPending
    {
        get { return (bool)GetValue(ShowPendingProperty); }
        set { SetValue(ShowPendingProperty, value); }
    }
    
    #endregion
    

提交回复
热议问题