Beispiel #1
0
        internal static FrameworkElement CreateDefaultEditor(PropertyItem propertyItem)
        {
            ITypeEditor 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(TimeSpan))
            {
                editor = new TimeSpanEditor();
            }
            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();
            }

            return(editor.ResolveEditor(propertyItem));
        }
Beispiel #2
0
        internal static ITypeEditor CreateDefaultEditor(Type propertyType, TypeConverter typeConverter)
        {
            ITypeEditor editor = null;

            if (propertyType == typeof(bool) || propertyType == typeof(bool?))
            {
                editor = new CheckBoxEditor();
            }
            else if (propertyType == typeof(decimal) || propertyType == typeof(decimal?))
            {
                editor = new DecimalUpDownEditor();
            }
            else if (propertyType == typeof(double) || propertyType == typeof(double?))
            {
                editor = new DoubleUpDownEditor();
            }
            else if (propertyType == typeof(int) || propertyType == typeof(int?))
            {
                editor = new IntegerUpDownEditor();
            }
            else if (propertyType == typeof(short) || propertyType == typeof(short?))
            {
                editor = new ShortUpDownEditor();
            }
            else if (propertyType == typeof(long) || propertyType == typeof(long?))
            {
                editor = new LongUpDownEditor();
            }
            else if (propertyType == typeof(float) || propertyType == typeof(float?))
            {
                editor = new SingleUpDownEditor();
            }
            else if (propertyType == typeof(byte) || propertyType == typeof(byte?))
            {
                editor = new ByteUpDownEditor();
            }
            else if (propertyType == typeof(sbyte) || propertyType == typeof(sbyte?))
            {
                editor = new UpDownEditor <SByteUpDown, sbyte?>();
            }
            else if (propertyType == typeof(uint) || propertyType == typeof(uint?))
            {
                editor = new UpDownEditor <UIntegerUpDown, uint?>();
            }
            else if (propertyType == typeof(ulong) || propertyType == typeof(ulong?))
            {
                editor = new UpDownEditor <ULongUpDown, ulong?>();
            }
            else if (propertyType == typeof(ushort) || propertyType == typeof(ushort?))
            {
                editor = new UpDownEditor <UShortUpDown, ushort?>();
            }
            else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
            {
                editor = new DateTimeUpDownEditor();
            }
            else if ((propertyType == typeof(Color)))
            {
                editor = new ColorEditor();
            }
            else if (propertyType.IsEnum)
            {
                editor = new EnumComboBoxEditor();
            }
            else if (propertyType == typeof(TimeSpan))
            {
                editor = new TimeSpanEditor();
            }
            else if (propertyType == typeof(FontFamily) || propertyType == typeof(FontWeight) || propertyType == typeof(FontStyle) || propertyType == typeof(FontStretch))
            {
                editor = new FontComboBoxEditor();
            }
            else if (propertyType == typeof(object))
            {
                // If any type of object is possible in the property, default to the TextBoxEditor.
                // Useful in some case (e.g., Button.Content).
                // Can be reconsidered but was the legacy behavior on the PropertyGrid.
                editor = new TextBoxEditor();
            }
            else
            {
                Type listType = CollectionControl.GetListItemType(propertyType);

                if (listType != null)
                {
                    if (!listType.IsPrimitive && !listType.Equals(typeof(String)))
                    {
                        editor = new Editors.CollectionEditor();
                    }
                    else
                    {
                        editor = new Editors.PrimitiveTypeCollectionEditor();
                    }
                }
                else
                {
                    // If the type is not supported, check if there is a converter that supports
                    // string conversion to the object type. Use TextBox in theses cases.
                    // Otherwise, return a TextBlock editor since no valid editor exists.
                    editor = (typeConverter != null && typeConverter.CanConvertFrom(typeof(string)))
                                          ? (ITypeEditor) new TextBoxEditor()
                                          : (ITypeEditor) new TextBlockEditor();
                }
            }

            return(editor);
        }
        internal static FrameworkElement CreateDefaultEditor(PropertyItem propertyItem)
        {
            ITypeEditor 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(TimeSpan))
            {
                editor = new TimeSpanEditor();
            }
            else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch))
            {
                editor = new FontComboBoxEditor();
            }
            else
            {
                Type listType = CollectionEditor.GetListItemType(propertyItem.PropertyType);

                if (listType != null)
                {
                    if (!listType.IsPrimitive && !listType.Equals(typeof(String)))
                    {
                        editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor();
                    }
                    else
                    {
                        editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.PrimitiveTypeCollectionEditor();
                    }
                }
                else
                {
                    editor = new TextBoxEditor();
                }
            }

            return(editor.ResolveEditor(propertyItem));
        }