Example #1
0
        private List <PropertyItem> GetObjectProperties(object instance)
        {
            var propertyItems = new List <PropertyItem>();

            if (instance == null)
            {
                return(propertyItems);
            }

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

                if (!AutoGenerateProperties)
                {
                    List <PropertyDescriptor> specificProperties = new List <PropertyDescriptor>();
                    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, instance, this, descriptor.Name));
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO: handle this some how
            }

            return(propertyItems);
        }
Example #2
0
        internal static PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid, string bindingPath)
        {
            PropertyItem propertyItem = new PropertyItem(instance, property, grid, bindingPath);

            var binding = new Binding(bindingPath)
            {
                Source = instance,
                ValidatesOnExceptions = true,
                ValidatesOnDataErrors = true,
                Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay
            };

            propertyItem.SetBinding(PropertyItem.ValueProperty, binding);

            propertyItem.Editor = PropertyGridUtilities.GetTypeEditor(propertyItem, grid.EditorDefinitions);

            return(propertyItem);
        }
Example #3
0
        internal static FrameworkElement GetTypeEditor(PropertyItem propertyItem, EditorDefinitionCollection editorDefinitions)
        {
            //first check for an attribute editor
            FrameworkElement editor = PropertyGridUtilities.GetAttibuteEditor(propertyItem);

            //now look for a custom editor based on editor definitions
            if (editor == null)
            {
                editor = PropertyGridUtilities.GetCustomEditor(propertyItem, editorDefinitions);
            }

            //guess we have to use the default editor
            if (editor == null)
            {
                editor = PropertyGridUtilities.CreateDefaultEditor(propertyItem);
            }

            return(editor);
        }
Example #4
0
        private void LoadProperties(bool isCategorized)
        {
            if (_propertyItemsCache == null)
            {
                return;
            }

            //clear any filters first
            Filter = String.Empty;

            if (isCategorized)
            {
                Properties = PropertyGridUtilities.GetCategorizedProperties(_propertyItemsCache);
            }
            else
            {
                Properties = PropertyGridUtilities.GetAlphabetizedProperties(_propertyItemsCache);
            }
        }