Пример #1
0
        public static void BindEvents(
            System.Windows.Forms.Control control,
            string controlProperty,
            object source,
            string sourceProperty,
            System.Windows.Forms.ConvertEventHandler delegFormat,
            System.Windows.Forms.ConvertEventHandler delegParse)
        {
            System.Windows.Forms.Binding binding = control.DataBindings[controlProperty];

            if (binding != null)
            {
                control.DataBindings.Remove(binding);
            }

            binding = new System.Windows.Forms.Binding(controlProperty, source, sourceProperty);

            if (delegFormat != null)
            {
                binding.Format += new System.Windows.Forms.ConvertEventHandler(delegFormat);
            }

            if (delegParse != null)
            {
                binding.Parse += new System.Windows.Forms.ConvertEventHandler(delegParse);
            }

            control.DataBindings.Add(binding);
        }
 public BindingCompleteEventArgs(System.Windows.Forms.Binding binding, System.Windows.Forms.BindingCompleteState state, System.Windows.Forms.BindingCompleteContext context, string errorText, System.Exception exception, bool cancel) : base(cancel)
 {
     this.binding   = binding;
     this.state     = state;
     this.context   = context;
     this.errorText = (errorText == null) ? string.Empty : errorText;
     this.exception = exception;
 }
Пример #3
0
        /// <summary>
        /// Binds specified property of this configuration object to specified property of the passed control and adds created binding to the passed control's data bindings.
        /// This cause immediate write of this configuration property value to the control property.
        /// </summary>
        /// <param name="control"><see cref="System.Windows.Forms.Control"/> where binding is to be added.</param>
        /// <param name="controlPropertyName">Name of the control property that is to be bound.</param>
        /// <param name="objectPropertyName">Name of this configuration object property that is to be bound.</param>
        /// <remarks>Use nameof operator to get property names for best source code maintainability.</remarks>
        public void AddPropertyBinding(System.Windows.Forms.Control control, string controlPropertyName, string objectPropertyName)
        {
            var binding = new System.Windows.Forms.Binding(controlPropertyName, this, objectPropertyName, false, System.Windows.Forms.DataSourceUpdateMode.Never);

            _propertyBindings.Add(binding, control);
            control.DataBindings.Add(binding);
            binding.ControlUpdateMode = System.Windows.Forms.ControlUpdateMode.Never; //It is important to set this property after adding data binding to control, otherwise the control property won't get correct value.
        }
 public BindingCompleteEventArgs(System.Windows.Forms.Binding binding, System.Windows.Forms.BindingCompleteState state, System.Windows.Forms.BindingCompleteContext context, string errorText, System.Exception exception, bool cancel) : base(cancel)
 {
     this.binding = binding;
     this.state = state;
     this.context = context;
     this.errorText = (errorText == null) ? string.Empty : errorText;
     this.exception = exception;
 }
Пример #5
0
        public MainWindow()
        {
            InitializeComponent();

            System.Windows.Forms.Binding bindE = new System.Windows.Forms.Binding("Checked", this, nameof(Enable), false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
            chkDecoration.DataBindings.Add(bindE);

            System.Windows.Forms.Binding bindC = new System.Windows.Forms.Binding("Text", this, nameof(Comment), false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
            txtComment.DataBindings.Add(bindC);

            System.Windows.Forms.Binding bindF = new System.Windows.Forms.Binding("Text", this, nameof(FilePathIcon), false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged);
            txtPath.DataBindings.Add(bindF);
        }
 public BindingCompleteEventArgs(System.Windows.Forms.Binding binding, System.Windows.Forms.BindingCompleteState state, System.Windows.Forms.BindingCompleteContext context, string errorText, System.Exception exception) : this(binding, state, context, errorText, exception, true)
 {
 }
 public BindingCompleteEventArgs(System.Windows.Forms.Binding binding, System.Windows.Forms.BindingCompleteState state, System.Windows.Forms.BindingCompleteContext context) : this(binding, state, context, string.Empty, null, false)
 {
 }