Search code examples
c#winformsdata-bindingapplication-settings

How to bind a control boolean property to contrary of boolean application setting?


How to bind a control Boolean property to contrary of Boolean application setting?

For example I want to bind "Visible" property of a button to "!Flag", that "Flag" is a Boolean field in application settings.


Solution

  • An ApplicationSetting binding doesn't allow applying any expression to the value. The simple solution is to derive your own control from Button. For example:

    using System;
    using System.Windows.Forms;
    
    class MyButton : Button {
        public bool Invisible {
            get { return !Visible; }
            set { Visible = !value; }
        }
    }