Esempio n. 1
0
        /// <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();
            }
        }
Esempio n. 2
0
        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);
            }
        }