Exemplo n.º 1
0
        /// <summary>
        /// Creates registered control by its type. Uses registered cotnrol createor.
        /// If creator is not found null is returned.
        /// </summary>
        /// <typeparam name="ControlType">control type.</typeparam>
        /// <param name="window">window the control belongs to. PAssed to control creation cosntructor.</param>
        /// <param name="creationFlags">creations flags.</param>
        /// <returns>created control.</returns>
        internal ControlType CreateControl <ControlType>(Window window, CreationFlag creationFlags)
        {
            IControlsCreator creator     = null;
            String           controlType = null;

            foreach (KeyValuePair <String, KeyValuePair <Type, IControlsCreator> > c in this.controlCreators)
            {
                if (c.Value.Key == typeof(ControlType))
                {
                    creator     = c.Value.Value;
                    controlType = c.Key;

                    break;
                }
            }

            if (null == creator)
            {
                return(default(ControlType));
            }

            Control control = creator.CreateControl(window, creationFlags);

            if ((null != control) && (control is ControlType))
            {
                control.Type = controlType;
                control.SetEngine(this);

                return((ControlType)(Object)control);
            }
            else
            {
                return(default(ControlType));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers control creator. Use ControlsCreatorTemplate class.
        /// </summary>
        /// <param name="creator">control creator.</param>
        /// <param name="controlType">control type name.</param>
        /// <param name="type">control type.</param>
        public void RegisterControlsCreator(IControlsCreator creator, String controlType, Type type)
        {
            KeyValuePair <Type, IControlsCreator> ex;

            if (true == this.controlCreators.TryGetValue(controlType, out ex))
            {
                throw new Exception("Controls creator already exists");
            }

            if (null != creator)
            {
                this.controlCreators[controlType] = new KeyValuePair <System.Type, IControlsCreator>(type, creator);
            }
        }