コード例 #1
0
        private CategoryContainer GetDefaultHeaderCategoryContainer(string headerText)
        {
            if (categoryViews.ContainsKey(headerText))
            {
                return(categoryViews[headerText]);
            }

            CategoryContainer newCategory = new CategoryContainer();

            categoryViews.Add(headerText, newCategory);
            newCategory.Header = headerText;

            CategoryPanel.Children.Add(newCategory);

            return(newCategory);
        }
コード例 #2
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();
            }
        }
コード例 #3
0
        private CategoryContainer GetComponentCategoryContainer(IInspectableComponent component, string headerText)
        {
            string uniqueId = component.GetHashCode().ToString();

            if (categoryViews.ContainsKey(uniqueId))
            {
                return(categoryViews[uniqueId]);
            }

            CategoryContainer       newCategory = new CategoryContainer();
            ComponentCategoryHeader header      = new ComponentCategoryHeader();

            header.Header         = headerText;
            header.RemoveClicked += () =>
            {
                ComponentRemoved(component);
            };
            newCategory.Header = header;

            categoryViews.Add(uniqueId, newCategory);
            CategoryPanel.Children.Add(newCategory);
            return(newCategory);
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        /// <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);
        }