Exemplo n.º 1
0
        /// <summary>
        /// Adds or replaces a text dictionary binding to a control's property.
        /// </summary>
        /// <param name="control">Control to add the binding to.</param>
        /// <param name="propertyName">Name of the control's property to bind to the dictionary.</param>
        /// <param name="key">Text key to use for the binding.</param>
        public static void AddBinding(Control control, string propertyName, string key)
        {
            lock (controlBindings)
            {
                Dictionary <string, BindingData> propertyBindings;
                if (!controlBindings.TryGetValue(control, out propertyBindings))
                {
                    // This is the first bound property for the control
                    propertyBindings = new Dictionary <string, BindingData>();
                    controlBindings.Add(control, propertyBindings);

                    // Be notified when the control is disposed
                    control.Disposed += Control_Disposed;
                }

                BindingData bindingData;
                if (propertyBindings.TryGetValue(propertyName, out bindingData))
                {
                    // This property of the control is already bound, remove that first
                    // Remove the binding from the control
                    control.DataBindings.Remove(bindingData.Binding);

                    // Dispose of the Tx binding instance
                    bindingData.TxDictionaryBinding.Dispose();
                }

                // Add the new binding to the control and keep track of it
                TxDictionaryBinding db = new TxDictionaryBinding(key);
                bindingData = new BindingData(
                    db,
                    control.DataBindings.Add(propertyName, db, "Text"));
                propertyBindings[propertyName] = bindingData;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds or replaces a text dictionary binding to a control's property.
        /// </summary>
        /// <param name="control">Control to add the binding to.</param>
        /// <param name="propertyName">Name of the control's property to bind to the dictionary.</param>
        /// <param name="key">Text key to use for the binding.</param>
        public static void AddBinding(Control control, string propertyName, string key)
        {
            lock (controlBindings)
            {
                Dictionary<string, BindingData> propertyBindings;
                if (!controlBindings.TryGetValue(control, out propertyBindings))
                {
                    // This is the first bound property for the control
                    propertyBindings = new Dictionary<string, BindingData>();
                    controlBindings.Add(control, propertyBindings);

                    // Be notified when the control is disposed
                    control.Disposed += Control_Disposed;
                }

                BindingData bindingData;
                if (propertyBindings.TryGetValue(propertyName, out bindingData))
                {
                    // This property of the control is already bound, remove that first
                    // Remove the binding from the control
                    control.DataBindings.Remove(bindingData.Binding);

                    // Dispose of the Tx binding instance
                    bindingData.TxDictionaryBinding.Dispose();
                }

                // Add the new binding to the control and keep track of it
                TxDictionaryBinding db = new TxDictionaryBinding(key);
                bindingData = new BindingData(
                    db,
                    control.DataBindings.Add(propertyName, db, "Text"));
                propertyBindings[propertyName] = bindingData;
            }
        }
Exemplo n.º 3
0
 public BindingData(TxDictionaryBinding txDictionaryBinding, Binding binding)
 {
     TxDictionaryBinding = txDictionaryBinding;
     Binding = binding;
 }
Exemplo n.º 4
0
 public BindingData(TxDictionaryBinding txDictionaryBinding, Binding binding)
 {
     TxDictionaryBinding = txDictionaryBinding;
     Binding             = binding;
 }