public void AddControl(int buttonIndex, BindableControlBase control)
 {
     RemoveControl(buttonIndex);
     if (control != null)
     {
         control.PropertyChanged += new PropertyChangedEventHandler(control_PropertyChanged);
         controls.Add(control);
     }
 }
        public void RemoveControl(int buttonIndex)
        {
            BindableControlBase control = GetControl(buttonIndex);

            if (control != null)
            {
                control.PropertyChanged -= new PropertyChangedEventHandler(control_PropertyChanged);
                controls.Remove(control);
            }
        }
        /// <summary>
        /// Reuses existing object instances if the desired control type is already present
        /// </summary>
        public BindableControlBase GetOrCreate(int buttonIndex, Type controlType)
        {
            BindableControlBase control = GetControl(buttonIndex);

            if (control != null && controlType.Equals(control.GetType()))
            {
                return(control);
            }

            //Create new control
            ConstructorInfo constructor = controlType.GetConstructor(new Type[0]);

            if (constructor != null)
            {
                control = constructor.Invoke(null) as BindableControlBase;
                if (control != null)
                {
                    AddControl(buttonIndex, control);
                }
            }
            return(control);
        }