Esempio n. 1
0
        public static ValueEditorBase GetEditor(PropertyItem propertyItem, PropertyGridLabel label)
        {
            if (propertyItem == null)
            {
                throw new ArgumentNullException("propertyItem");
            }

            var attribute = propertyItem.GetAttribute <EditorAttribute>();

            if (attribute != null)
            {
                var editorType = Type.GetType(attribute.EditorTypeName, true);
                if (editorType != null)
                {
                    return(Activator.CreateInstance(editorType, label, propertyItem) as ValueEditorBase);
                }
            }

            var propertyType = propertyItem.PropertyType;

            var editor = GetEditor(propertyType, label, propertyItem);

            while (editor == null && propertyType.BaseType != null)
            {
                propertyType = propertyType.BaseType;
                editor       = GetEditor(propertyType, label, propertyItem);
            }

            return(editor);
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="label"></param>
        /// <param name="property"></param>
        public DateTimeValueEditor(PropertyGridLabel label, PropertyItem property)
            : base(label, property)
        {
            currentValue              = property.Value;
            property.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(property_PropertyChanged);
            property.ValueError      += new EventHandler <ExceptionEventArgs>(property_ValueError);

            pnl          = new StackPanel();
            this.Content = pnl;

            dtp                     = new DatePicker();
            dtp.Visibility          = Visibility.Visible;
            dtp.Margin              = new Thickness(0);
            dtp.Padding             = new Thickness(2);
            dtp.VerticalAlignment   = VerticalAlignment.Center;
            dtp.HorizontalAlignment = HorizontalAlignment.Stretch;
            dtp.CalendarOpened     += new RoutedEventHandler(dtp_CalendarOpened);
            dtp.CalendarClosed     += new RoutedEventHandler(dtp_CalendarClosed);
            dtp.LostFocus          += new RoutedEventHandler(dtp_LostFocus);
            dtp.Background          = new SolidColorBrush(Colors.White);
            dtp.Foreground          = this.Property.CanWrite ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.Gray);

            pnl.Children.Add(dtp);
            dtp.Focus();

            this.ShowTextBox();
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="label"></param>
        /// <param name="property"></param>
        public ComboBoxEditorBase(PropertyGridLabel label, PropertyItem property)
            : base(label, property)
        {
            currentValue              = property.Value;
            property.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(property_PropertyChanged);
            property.ValueError      += new EventHandler <ExceptionEventArgs>(property_ValueError);

            cbo                     = new ComboBox();
            cbo.Visibility          = Visibility.Collapsed;
            cbo.Margin              = new Thickness(0);
            cbo.Padding             = new Thickness(2);
            cbo.VerticalAlignment   = VerticalAlignment.Center;
            cbo.HorizontalAlignment = HorizontalAlignment.Stretch;
            cbo.DropDownOpened     += new EventHandler(cbo_DropDownOpened);
            cbo.LostFocus          += new RoutedEventHandler(cbo_LostFocus);
            cbo.Background          = new SolidColorBrush(Colors.White);
            cbo.Foreground          = this.Property.CanWrite ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.Gray);

            this.InitializeCombo();

            pnl = new StackPanel();
            pnl.Children.Add(cbo);

            this.ShowTextBox();

            this.Content = pnl;
        }
Esempio n. 4
0
 static Border GetItemLabel(PropertyGridLabel label, string tagValue)
 {
     return(new Border()
     {
         Name = Guid.NewGuid().ToString("N"),
         Margin = new Thickness(0),
         BorderBrush = new SolidColorBrush(backgroundColor),
         BorderThickness = new Thickness(0, 0, 1, 1),
         Child = label,
         Tag = tagValue
     });
 }
        public NestedObjectValueEditor(PropertyGridLabel label, PropertyItem property)
            : base(label, property)
        {
            property.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(property_PropertyChanged);
            property.ValueError      += new EventHandler <ExceptionEventArgs>(property_ValueError);

            panel = new Grid();
            panel.ColumnDefinitions.Add(new ColumnDefinition());
            panel.ColumnDefinitions.Add(new ColumnDefinition());
            panel.Height = 20;
            this.Content = panel;

            txt = new TextBox();
            //txt.Height = 20;
            if (null != property.Value)
            {
                txt.Text = property.Value.ToString();
            }
            txt.IsReadOnly        = true;
            txt.Foreground        = this.Property.CanWrite ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.Gray);
            txt.BorderThickness   = new Thickness(0);
            txt.Margin            = new Thickness(0);
            txt.Padding           = new Thickness(0);
            txt.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            txt.SetValue(Grid.ColumnProperty, 0);
            if (this.Property.CanWrite)
            {
                txt.TextChanged += new TextChangedEventHandler(Control_TextChanged);
            }
            panel.Children.Add(txt);

            if (null != property.Value)
            {
                button = new Button()
                {
                    Content = "..."
                };
                button.Click += new RoutedEventHandler(button_Click);
                button.Margin = new Thickness(1);
                button.SetValue(Grid.ColumnProperty, 1);
                panel.Children.Add(button);
                panel.ColumnDefinitions[1].Width = new GridLength(20);
            }
            else
            {
                Grid.SetColumnSpan(txt, 2);
            }

            this.GotFocus += new RoutedEventHandler(StringValueEditor_GotFocus);
        }
Esempio n. 6
0
        public ValueEditorBase(PropertyGridLabel label, PropertyItem property)
        {
            Label = label;
            Label.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Label_MouseLeftButtonDown);
            Label.MouseLeftButtonUp   += new System.Windows.Input.MouseButtonEventHandler(Label_MouseLeftButtonUp);
            if (!property.CanWrite)
            {
                Label.Foreground = new SolidColorBrush(Colors.Gray);
            }

            Property                   = property;
            BorderThickness            = new Thickness(0);
            Margin                     = new Thickness(0);
            HorizontalAlignment        = HorizontalAlignment.Stretch;
            HorizontalContentAlignment = HorizontalAlignment.Stretch;
        }
Esempio n. 7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="label"></param>
        /// <param name="property"></param>
        public BooleanValueEditor(PropertyGridLabel label, PropertyItem property)
            : base(label, property)
        {
            property.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(property_PropertyChanged);

            checkBox                   = new CheckBox();
            checkBox.Margin            = new Thickness(2);
            checkBox.VerticalAlignment = VerticalAlignment.Center;
            checkBox.IsEnabled         = this.Property.CanWrite;
            checkBox.IsChecked         = (bool)property.Value;

            checkBox.Checked   += new RoutedEventHandler(checkBox_Checked);
            checkBox.Unchecked += new RoutedEventHandler(checkBox_Unchecked);

            this.Content = checkBox;
        }
Esempio n. 8
0
        public static ValueEditorBase GetEditor(Type propertyType, PropertyGridLabel label, PropertyItem property)
        {
            if (typeof(Boolean).IsAssignableFrom(propertyType))
            {
                return(new BooleanValueEditor(label, property));
            }

            if (typeof(Enum).IsAssignableFrom(propertyType))
            {
                return(new EnumValueEditor(label, property));
            }

            if (typeof(DateTime).IsAssignableFrom(propertyType))
            {
                return(new DateTimeValueEditor(label, property));
            }

            if (typeof(String).IsAssignableFrom(propertyType))
            {
                return(new StringValueEditor(label, property));
            }

            if (typeof(ValueType).IsAssignableFrom(propertyType))
            {
                return(new StringValueEditor(label, property));
            }

            if (typeof(IList).IsAssignableFrom(propertyType))
            {
                return(new CollectionValueEditor(label, property));
            }

            if (typeof(Object).IsAssignableFrom(propertyType))
            {
                return(new NestedObjectValueEditor(label, property));
            }

            return(new StringValueEditor(label, property));
        }
Esempio n. 9
0
 public EnumValueEditor(PropertyGridLabel label, PropertyItem property)
     : base(label, property)
 {
 }
Esempio n. 10
0
        public StringValueEditor(PropertyGridLabel label, PropertyItem property)
            : base(label, property)
        {
            if (property.PropertyType == typeof(Char))
            {
                if ((char)property.Value == '\0')
                {
                    property.Value = "";
                }
            }

            property.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(property_PropertyChanged);
            property.ValueError      += new EventHandler <ExceptionEventArgs>(property_ValueError);

            var grid = new Grid();

            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.ColumnDefinitions.Add(new ColumnDefinition());
            grid.Height  = 20;
            this.Content = grid;

            textBox        = new TextBox();
            textBox.Height = 20;
            if (null != property.Value)
            {
                textBox.Text = property.Value.ToString();
            }
            textBox.IsReadOnly      = !this.Property.CanWrite;
            textBox.Foreground      = this.Property.CanWrite ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.Gray);
            textBox.Background      = new SolidColorBrush(Colors.White);
            textBox.BorderThickness = new Thickness(0);
            textBox.Margin          = new Thickness(0);
            textBox.Padding         = new Thickness(2);
            textBox.GotFocus       += new RoutedEventHandler(textBox_GotFocus);
            textBox.AcceptsReturn   = true;

            grid.Children.Add(textBox);

            if (this.Property.CanWrite)
            {
                textBox.TextChanged += new TextChangedEventHandler(Control_TextChanged);
            }

            if (this.Property.CanWrite && property.PropertyType == typeof(string))
            {
                button = new Button()
                {
                    Content = "..."
                };
                button.Click += new RoutedEventHandler(button_Click);
                button.Margin = new Thickness(1);
                button.SetValue(Grid.ColumnProperty, 1);
                grid.Children.Add(button);
                grid.ColumnDefinitions[1].Width = new GridLength(20);
            }
            else
            {
                Grid.SetColumnSpan(textBox, 2);
            }

            this.GotFocus += new RoutedEventHandler(StringValueEditor_GotFocus);
        }