Esempio n. 1
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);
        }
Esempio n. 2
0
        private PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid)
        {
            PropertyItem propertyItem = new PropertyItem(instance, property, grid);

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

            propertyItem.SetBinding(PropertyItem.ValueProperty, binding);

            ITypeEditor editor = null;

            //check for custom editor
            if (CustomTypeEditors.Count > 0)
            {
                //first check if the custom editor is type based
                ICustomTypeEditor customEditor = CustomTypeEditors[propertyItem.PropertyType];
                if (customEditor == null)
                {
                    //must be property based
                    customEditor = CustomTypeEditors[propertyItem.Name];
                }

                if (customEditor != null)
                {
                    editor = customEditor.Editor;
                }
            }

            try
            {
                //no custom editor found
                if (editor == null)
                {
                    if (propertyItem.IsReadOnly)
                    {
                        editor = new TextBlockEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(bool) || propertyItem.PropertyType == typeof(bool?))
                    {
                        editor = new CheckBoxEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal?))
                    {
                        editor = new DecimalUpDownEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(double) || propertyItem.PropertyType == typeof(double?))
                    {
                        editor = new DoubleUpDownEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?))
                    {
                        editor = new IntegerUpDownEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(DateTime) || propertyItem.PropertyType == typeof(DateTime?))
                    {
                        editor = new DateTimeUpDownEditor();
                    }
                    else if ((propertyItem.PropertyType == typeof(Color)))
                    {
                        editor = new ColorEditor();
                    }
                    else if (propertyItem.PropertyType.IsEnum)
                    {
                        editor = new EnumComboBoxEditor();
                    }
                    else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch))
                    {
                        editor = new FontComboBoxEditor();
                    }
                    else if (propertyItem.PropertyType.IsGenericType)
                    {
                        if (propertyItem.PropertyType.GetInterface("IList") != null)
                        {
                            var t = propertyItem.PropertyType.GetGenericArguments()[0];
                            if (!t.IsPrimitive && !t.Equals(typeof(String)))
                            {
                                editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.CollectionEditor();
                            }
                            else
                            {
                                editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.PrimitiveTypeCollectionEditor();
                            }
                        }
                        else
                        {
                            editor = new TextBlockEditor();
                        }
                    }
                    else
                    {
                        editor = new TextBoxEditor();
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO: handle this some how
            }

            editor.Attach(propertyItem);
            propertyItem.Editor = editor.ResolveEditor();

            return(propertyItem);
        }
Esempio n. 3
0
        internal static PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid, string bindingPath, int level)
        {
            PropertyItem item = CreatePropertyItem(property, instance, grid, bindingPath);

            item.Level = level;
            return(item);
        }