Beispiel #1
0
        protected virtual void OnIsExpandedChanged(bool oldValue, bool newValue)
        {
            if (newValue && Properties.Count == 0 && (this.ChildrenDefinitions != null))
            {
                IEnumerable <PropertyItem> children = this.ChildrenDefinitions
                                                      .Select(
                    (def) =>
                {
                    PropertyItem subProperty = PropertyGridUtilities.CreatePropertyItem(def);
                    subProperty.Level        = Level + 1;
                    return(subProperty);
                });

                Properties.Update(children, false, null);
            }
        }
Beispiel #2
0
        private List <PropertyItem> GeneratePropertyItems(object instance)
        {
            var propertyItems = new List <PropertyItem>();

            if (instance != null)
            {
                try
                {
                    PropertyDescriptorCollection descriptors = PropertyGridUtilities.GetPropertyDescriptors(instance);

                    if (!AutoGenerateProperties)
                    {
                        List <PropertyDescriptor> specificProperties = new List <PropertyDescriptor>();
                        if (PropertyDefinitions != null)
                        {
                            foreach (PropertyDefinition pd in PropertyDefinitions)
                            {
                                foreach (PropertyDescriptor descriptor in descriptors)
                                {
                                    if (descriptor.Name == pd.Name)
                                    {
                                        specificProperties.Add(descriptor);
                                        break;
                                    }
                                }
                            }
                        }

                        descriptors = new PropertyDescriptorCollection(specificProperties.ToArray());
                    }

                    foreach (PropertyDescriptor descriptor in descriptors)
                    {
                        if (descriptor.IsBrowsable)
                        {
                            propertyItems.Add(PropertyGridUtilities.CreatePropertyItem(descriptor, this));
                        }
                    }
                }
                catch (Exception)
                {
                    //TODO: handle this some how
                }
            }

            return(propertyItems);
        }