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);

            txt = new TextBox();
            txt.Height = 20;
            if (null != property.Value)
                txt.Text = property.Value.ToString();
            //txt.IsReadOnly = !this.Property.CanWrite;
            txt.Foreground = this.Property.CanWrite ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.Gray);
            txt.BorderThickness = new Thickness(0);
            txt.Margin = new Thickness(0);
            txt.LostFocus += new RoutedEventHandler(txt_LostFocus);

            if (this.Property.CanWrite)
                txt.TextChanged += new TextChangedEventHandler(Control_TextChanged);

            this.Content = txt;
            this.GotFocus += new RoutedEventHandler(StringValueEditor_GotFocus);
        }
        public RecursePropertiesButton(PropertyGridLabel label, PropertyItem property)
            : base(label, property)
        {
            var button = new Button();
            button.Margin = new Thickness(0);
            button.VerticalAlignment = VerticalAlignment.Center;
            button.HorizontalAlignment = HorizontalAlignment.Stretch;
            button.Content = "Edit Properties";
            button.Visibility = property.Value == null ? System.Windows.Visibility.Collapsed : Visibility.Visible;
            button.Click += (s, e) => InvokeRecurseProperties(EventArgs.Empty);

            var grid = new Grid();
            grid.Children.Add(button);

            this.Content = grid;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="label">The associated label for this Editor control</param>
        /// <param name="property">The associated PropertyItem for this control</param>
        public ValueEditorBase(PropertyGridLabel label, PropertyItem property)
        {
            this.Label = label;
            this.Label.Name = "lbl" + property.Name;
            this.Label.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(Label_MouseLeftButtonDown);
            this.Label.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(Label_MouseLeftButtonUp);
            if (!property.CanWrite)
                this.Label.Foreground = new SolidColorBrush(Colors.Gray);

            this.Name = "txt" + property.Name;
            this.Property = property;
            this.BorderThickness = new Thickness(0);
            this.Margin = new Thickness(0);
            this.HorizontalAlignment = HorizontalAlignment.Stretch;
            this.HorizontalContentAlignment = HorizontalAlignment.Stretch;
        }
Example #4
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 (_validValueTypes.Contains((propertyType)))
                return new StringValueEditor(label, property);

            //if (typeof(Object).IsAssignableFrom(propertyType))
            //    return new PropertyGrid(label, property);

            return new RecursePropertiesButton(label, property);
        }
        /// <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.VerticalAlignment = VerticalAlignment.Center;
            cbo.HorizontalAlignment = HorizontalAlignment.Stretch;
            cbo.DropDownOpened += new EventHandler(cbo_DropDownOpened);
            cbo.LostFocus += new RoutedEventHandler(cbo_LostFocus);
            this.InitializeCombo();

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

            this.ShowTextBox();

            this.Content = pnl;
        }
        /// <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.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);
            pnl.Children.Add(dtp);
            dtp.Focus();

            this.ShowTextBox();
        }
Example #7
0
        public static ValueEditorBase GetEditor(PropertyItem propertyItem, PropertyGridLabel label)
        {
            if (propertyItem == null) throw new ArgumentNullException("propertyItem");

            EditorAttribute attribute = propertyItem.GetAttribute<EditorAttribute>();
            if (attribute != null)
            {
                Type editorType = Type.GetType(attribute.EditorTypeName, false);
                if (editorType != null)
                    return Activator.CreateInstance(editorType) as ValueEditorBase;
            }

            Type propertyType = propertyItem.PropertyType;

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

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

            return editor;
        }
 public BooleanValueEditor(PropertyGridLabel label, PropertyItem property)
     : base(label, property)
 {
 }
 public EnumValueEditor(PropertyGridLabel label, PropertyItem property)
     : base(label, property)
 {
 }
Example #10
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
     };
 }