/// <summary>
        /// Adds a property to the UI
        /// </summary>
        /// <param name="property"></param>
        /// <param name="propertyMetadata"></param>
        private void AddProperty(InspectableProperty property, InspectablePropertyMetadata propertyMetadata, CategoryContainer container)
        {
            //Get the category of the property if its not set
            //CategoryContainer container = GetCategoryContainer(propertyMetadata);

            ValueControl      valueControl;
            PropertyContainer propContainer;

            //Check if the property has a custom control
            if (propertyMetadata.HasCustomControl)
            {
                valueControl = propertyMetadata.CustomControlFactory.GetControl(property);
            }
            else
            {
                valueControl = controlFactory.GetControl(property);
            }
            //If the edit mode is set to on focus, create a textblock for when its not
            if (valueControl.EditBehaviour == EditingBehaviour.OnFocus)
            {
                TextBlock unfocusElement = controlFactory.CreateUnFocusedTextBlock(property.ReflectionData.Name, property.Target);
                propContainer = new PropertyContainer(propertyMetadata.Name, valueControl, unfocusElement);
            }
            else
            {
                propContainer = new PropertyContainer(propertyMetadata.Name, valueControl);
            }
            container.AddProperty(propContainer);
        }
Example #2
0
        private static InspectablePropertyMetadata GenerateMetaData(InspectableProperty property)
        {
            //Get all attributes
            object[] attributes = property.ReflectionData.GetCustomAttributes(false);
            //Check for update on prop change attribute
            bool updateLayout = attributes
                                .Any(x => x.GetType() == typeof(UpdatePropListOnPropChangeAttribute));

            CategoryAttribute categoryAttribute = attributes
                                                  .FirstOrDefault(x => x is CategoryAttribute)
                                                  as CategoryAttribute;

            //Set category name to the default
            string categoryName = String.Empty;

            //Change it to the value of category attribute if it exists
            if (categoryAttribute != null)
            {
                categoryName = categoryAttribute.Category;
            }
            else
            {
                //Do a last check for display name on the source class (target) of the property
                DisplayNameAttribute categoryDisplayName = property.Target.GetType()
                                                           .GetFirstOrDefaultAttribute <DisplayNameAttribute>();

                if (categoryDisplayName != null)
                {
                    categoryName = categoryDisplayName.DisplayName;
                }
            }

            //If there is no category yet, should we use Target toString as category or the default
            if (categoryName == string.Empty)
            {
                categoryName = property.Target.ToString();
            }

            //Get DisplayName if any
            string displayName = (attributes.FirstOrDefault(x => x is DisplayNameAttribute) as DisplayNameAttribute)?.DisplayName;

            var metaData = new InspectablePropertyMetadata(updateLayout, categoryName, property.ReflectionData);

            metaData.DisplayName = displayName;
            return(metaData);
        }
        /// <summary>
        /// Update the Grid with a new target
        /// </summary>
        /// <param name="oldObject">the previous object edited</param>
        /// <param name="newObject">the new object being edited</param>
        private void UpdatePropertyGridTarget(object oldObject, object newObject)
        {
            Cleanup();
            ClearGridUI();
            ResetCategories();

            if (newObject != null)
            {
                componentMode = newObject is IComponentContainer;

                //ComponentContainers and PropertyProviders are handled differently with regards to
                //how they are categorizer and put into category containers
                //as well as the possible header of the category container
                if (componentMode)
                {
                    IComponentContainer componentContainer = newObject as IComponentContainer;
                    foreach (IInspectableComponent component in componentContainer.GetInspectableComponents())
                    {
                        AddInspectableComponent(component);
                    }
                    //Listen for component added/removed events
                    componentContainer.ComponentAdded += ComponentContainer_ComponentAdded;
                    //componentContainer.ComponentRemoved
                    //Add the button at the bottom to pick components
                    AddBehaviourButton();
                }
                else
                {
                    foreach (InspectableProperty property in DefaultPropertyFactory.GetProperties(newObject))
                    {
                        InspectablePropertyMetadata propertyMetadata = DefaultPropertyFactory.GetPropertyMetadata(property);
                        CategoryContainer           container        = GetDefaultHeaderCategoryContainer(propertyMetadata.Category);
                        ListenToPropertyChanged(property);
                        AddProperty(property, propertyMetadata, container);
                    }
                }
            }
            else
            {
                SetEmptyGridUi();
            }
        }
        private void AddInspectableComponent(IInspectableComponent component)
        {
            InspectableProperty[] properties = component.Properties;
            //Add Container independently of any properties
            ComponentDescriptor descriptor = ComponentDescriptorCache.GetDescriptor(component);
            CategoryContainer   container  = null;

            if (descriptor.Removable)
            {
                container = GetComponentCategoryContainer(component, descriptor.Title);
            }
            else
            {
                container = GetDefaultHeaderCategoryContainer(descriptor.Title);
            }
            foreach (InspectableProperty property in properties)
            {
                InspectablePropertyMetadata propertyMetadata = DefaultPropertyFactory.GetPropertyMetadata(property);

                ListenToPropertyChanged(property);
                AddProperty(property, propertyMetadata, container);
            }
        }
 /// <summary>
 /// Removes a property from the UI
 /// </summary>
 /// <param name="property"></param>
 private void RemoveProperty(InspectablePropertyMetadata property)
 {
 }