Ejemplo n.º 1
0
        public ImageVaueEditor(PropertyGridLabel label, PropertyItem property)
            : base(label, property)
        {
            property.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(property_PropertyChanged);
            property.ValueError += new EventHandler<ExceptionEventArgs>(property_ValueError);

            _attribute = property.GetAttribute<ImageAttribute>();

            if(null == _attribute)
            {
                _attribute = new ImageAttribute();
                _attribute.OnlyImage = false;
            }
            _grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1d, GridUnitType.Auto) });
            _grid.ColumnDefinitions.Add(new ColumnDefinition());
            _grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1d, GridUnitType.Auto) });
            _grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1d, GridUnitType.Auto) });
            _grid.Children.Add(_image);
            _grid.Children.Add(_text);
            _grid.Children.Add(_removeButton);
            _grid.Children.Add(_broswerButton);
            _image.SetValue(Grid.ColumnProperty, 0);
            _text.SetValue(Grid.ColumnProperty, 1);
            _removeButton.SetValue(Grid.ColumnProperty, 2);
            _broswerButton.SetValue(Grid.ColumnProperty, 3);
            this.Content = _grid;
            _broswerButton.Click += BroswerButton_Click;
            _removeButton.Click += RemoveButton_Click;
            UpdateLabel(property.Value);
            _text.GotFocus += Text_GotFocus;
            _text.Background = null;
            _text.BorderBrush = null;
            _text.BorderThickness = new Thickness();
        }
Ejemplo n.º 2
0
        protected virtual FrameworkElement CreateCommandLinkControl(PropertyItem property)
        {
            var commandAtt = property.Descriptor.Attributes.OfType <Attribute>().FirstOrDefault(att => att is IPrefabCommand) as IPrefabCommand;


            var c = new CommandLinkBlock {
                PrefabInvocation = commandAtt, VerticalAlignment = VerticalAlignment.Center, TextDecorations = TextDecorations.Underline
            };

            if (property.GetAttribute <AssignCommandDataAttribute>() != null)
            {
                c.CommandDataAssignment = true;
            }


            c.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding(property.Descriptor.Name));
            c.SetBinding(CommandLinkBlock.CommandProperty, property.CreateBinding());

            if (c.CommandDataAssignment)
            {
                c.SetBinding(CommandLinkBlock.CommandDataProperty,
                             new System.Windows.Data.Binding("SelectedObject")
                {
                    RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(PropertyControlEx), 1), Mode = BindingMode.OneWay
                });
            }

            return(c);
        }
Ejemplo n.º 3
0
        protected override FrameworkElement CreateDefaultControl(PropertyItem pi)
        {
            var rla = pi.GetAttribute <ReferenceLookupAttribute>();

            if (rla != null)
            {
                if (pi.Is(typeof(string)))
                {
                    pi.Converter = new ReferenceLookupConverter {
                        LookupKey = rla.LookupKey
                    };
                }
                else if (pi.Is(typeof(IEnumerable)))
                {
                    pi.Converter = new ReferenceListLookupConverter {
                        LookupKey = rla.LookupKey
                    };
                }
                else
                {
                    pi.Converter = null;
                }
            }

            return(base.CreateDefaultControl(pi));
        }
Ejemplo n.º 4
0
        protected override FrameworkElement CreateDefaultControl(PropertyItem property)
        {
            var controlAttribute = property.GetAttribute <CustomEditorAttribute>();

            if (controlAttribute != null)
            {
                var control = (FrameworkElement)Activator.CreateInstance(controlAttribute.ControlType);
                control.VerticalAlignment = VerticalAlignment.Center;
                control.SetBinding(FrameworkElement.DataContextProperty, property.CreateBinding());

                return(control);
            }

            property.AutoUpdateText = true;
            return(base.CreateDefaultControl(property));
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        public override FrameworkElement CreateControl(PropertyItem pi, PropertyControlFactoryOptions options)
        {
            FrameworkElement retval = null;

            if (pi.Is(typeof(CommandProperty)))
            {
                pi.HeaderPlacement = HeaderPlacement.Collapsed;
                retval             = CreateCommandLinkControl(pi);
            }
            else if (pi.GetAttribute <NestedPropertiesAttribute>() != null)
            {
                if (pi.Is(typeof(ICollection)) || pi.Is(typeof(ICollection <>)))
                {
                    retval = CreateNestedPropertyGridsControl(pi);
                }
                else
                {
                    retval = CreateNestedPropertyGridControl(pi);
                }
            }
            else
            {
                var rla = pi.GetAttribute <ReferenceLookupAttribute>();
                if (rla != null)
                {
                    if (pi.Is(typeof(string)))
                    {
                        pi.Converter = new ReferenceListLookupConverter {
                            LookupKey = rla.LookupKey
                        };
                        pi.ItemsSource = ReferenceLookupList.GetCompleteList(rla.LookupKey);

                        retval = this.CreateBindableComboBoxControl(pi, rla.LookupKey);
                    }
                    else if (pi.Is(typeof(IEnumerable)))
                    {
                        pi.Converter = new ReferenceListLookupConverter {
                            LookupKey = rla.LookupKey
                        };
                        pi.ItemsSource = ReferenceLookupList.GetCompleteList(rla.LookupKey);

                        retval = this.CreateBindableMultipleSelectControl(pi, rla.LookupKey);
                    }
                    else
                    {
                        pi.Converter = new ReferenceLookupConverter {
                            LookupKey = rla.LookupKey
                        };
                        retval = base.CreateDefaultControl(pi);
                    }
                }
                else
                {
                    retval = base.CreateControl(pi, options);
                }
            }

            retval.Name = pi.Descriptor.Name + "PropertyPageElem";

            return(retval);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Sets the properties.
        /// </summary>
        /// <param name="pi">The property item.</param>
        /// <param name="instance">The instance.</param>
        protected virtual void SetProperties(PropertyItem pi, object instance)
        {
            var tabName = this.DefaultTabName ?? instance.GetType().Name;
            var categoryName = this.DefaultCategoryName;

            // find the declaring type
            Type declaringType = pi.Descriptor.ComponentType;
            var propertyInfo = instance.GetType().GetProperty(pi.Descriptor.Name);
            if (propertyInfo != null)
            {
                declaringType = propertyInfo.DeclaringType;
            }

            if (declaringType != this.CurrentDeclaringType)
            {
                this.CurrentCategory = null;
            }

            this.CurrentDeclaringType = declaringType;

            if (!this.InheritCategories)
            {
                this.CurrentCategory = null;
            }

            var ca = pi.GetAttribute<LocalizableCategory>();
            if (ca != null)
            {
                this.CurrentCategory = ca.LocalizedCategory;
                this.CurrentCategoryDeclaringType = declaringType;
            }

            var category = this.CurrentCategory ?? (this.DefaultCategoryName ?? pi.Descriptor.Category);

            if (category != null)
            {
                var items = category.Split('|');
                if (items.Length == 2)
                {
                    tabName = items[0];
                    categoryName = items[1];
                }

                if (items.Length == 1)
                {
                    categoryName = items[0];
                }
            }

            var displayName = this.GetDisplayName(pi.Descriptor, declaringType);
            var description = this.GetDescription(pi.Descriptor, declaringType);

            pi.DisplayName = this.GetLocalizedString(displayName, declaringType);
            pi.Description = this.GetLocalizedDescription(description, declaringType);

            pi.Category = this.GetLocalizedString(categoryName, this.CurrentCategoryDeclaringType);
            pi.Tab = this.GetLocalizedString(tabName, this.CurrentCategoryDeclaringType);

            // pi.CategoryDescription = this.GetLocalizedDescription(categoryName, this.CurrentCategoryDeclaringType);
            // pi.TabDescription = this.GetLocalizedDescription(tabName, this.CurrentCategoryDeclaringType);

            // Find descriptors by convention
            pi.IsEnabledDescriptor = pi.GetDescriptor(string.Format(this.EnabledPattern, pi.PropertyName));
            pi.IsVisibleDescriptor = pi.GetDescriptor(string.Format(this.VisiblePattern, pi.PropertyName));
            pi.OptionalDescriptor = pi.GetDescriptor(string.Format(this.OptionalPattern, pi.PropertyName));

            foreach (Attribute attribute in pi.Descriptor.Attributes)
            {
                this.SetAttribute(attribute, pi, instance);
            }

            pi.IsOptional = pi.OptionalDescriptor != null;

            if (pi.IsComment)
            {
                pi.HeaderPlacement = HeaderPlacement.Hidden;
            }

            if (pi.Descriptor.PropertyType == typeof(TimeSpan) && pi.Converter == null)
            {
                pi.Converter = new TimeSpanToStringConverter();
                pi.ConverterParameter = pi.FormatString;
            }
        }
        /// <summary>
        /// Sets the properties.
        /// </summary>
        /// <param name="pi">
        /// The property item.
        /// </param>
        protected virtual void SetProperties(PropertyItem pi)
        {
            var pd = pi.Descriptor;
            var properties = pi.Properties;

            var tabName = this.DefaultTabName ?? pi.Instance.GetType().Name;
            var categoryName = this.DefaultCategoryName;

            // find the declaring type
            Type declaringType = pi.Descriptor.ComponentType;
            var propertyInfo = pi.Instance.GetType().GetProperty(pi.Descriptor.Name);
            if (propertyInfo != null)
            {
                declaringType = propertyInfo.DeclaringType;
            }

            if (declaringType != this.CurrentDeclaringType)
            {
                this.CurrentCategory = null;
            }

            this.CurrentDeclaringType = declaringType;

            if (!this.InheritCategories)
            {
                this.CurrentCategory = null;
            }

            var ca = AttributeHelper.GetFirstAttribute<CategoryAttribute>(pd);
            if (ca != null)
            {
                this.CurrentCategory = ca.Category;
                this.CurrentCategoryDeclaringType = declaringType;
            }

            var category = this.CurrentCategory ?? (this.DefaultCategoryName ?? pd.Category);

            if (category != null)
            {
                var items = category.Split('|');
                if (items.Length == 2)
                {
                    tabName = items[0];
                    categoryName = items[1];
                }

                if (items.Length == 1)
                {
                    categoryName = items[0];
                }
            }

            var displayName = this.GetDisplayName(pd, declaringType);
            var description = this.GetDescription(pd, declaringType);

            pi.DisplayName = this.GetLocalizedString(displayName, declaringType);
            pi.Description = this.GetLocalizedDescription(description, declaringType);

            pi.Category = this.GetLocalizedString(categoryName, this.CurrentCategoryDeclaringType);
            pi.CategoryDescription = this.GetLocalizedDescription(categoryName, this.CurrentCategoryDeclaringType);
            pi.Tab = this.GetLocalizedString(tabName, this.CurrentCategoryDeclaringType);
            pi.TabDescription = this.GetLocalizedDescription(tabName, this.CurrentCategoryDeclaringType);

            // Find descriptors by convention
            pi.IsEnabledDescriptor = pi.GetDescriptor(string.Format(this.EnabledPattern, pd.Name));
            pi.IsVisibleDescriptor = pi.GetDescriptor(string.Format(this.VisiblePattern, pd.Name));
            pi.OptionalDescriptor = pi.GetDescriptor(string.Format(this.OptionalPattern, pd.Name));

            pi.UseRadioButtons = pi.GetAttribute<RadioButtonsAttribute>() != null;
            var fp = pi.GetAttribute<FontPreviewAttribute>();
            pi.PreviewFonts = fp != null;
            if (fp != null)
            {
                pi.FontSize = fp.Size;
                pi.FontWeight = fp.Weight;
                pi.FontFamilyPropertyDescriptor = pi.GetDescriptor(fp.FontFamilyPropertyName);
            }

            var fpa = pi.GetAttribute<FilePathAttribute>();
            pi.IsFilePath = fpa != null;
            if (fpa != null)
            {
                pi.FilePathFilter = fpa.Filter;
                pi.FilePathDefaultExtension = fpa.DefaultExtension;
                pi.IsFileOpenDialog = fpa.UseOpenDialog;
            }

            var dpa = pi.GetAttribute<DirectoryPathAttribute>();
            pi.IsDirectoryPath = dpa != null;

            foreach (var da in pi.GetAttributes<DataTypeAttribute>())
            {
                pi.DataTypes.Add(da.DataType);
                switch (da.DataType)
                {
                    case DataType.MultilineText:
                        pi.AcceptsReturn = true;
                        break;
                    case DataType.Password:
                        pi.IsPassword = true;
                        break;
                }
            }

            foreach (var da in pi.GetAttributes<ColumnAttribute>())
            {
                pi.Columns.Add(da);
            }

            var la = pi.GetAttribute<ListAttribute>();
            if (la != null)
            {
                pi.ListCanAdd = la.CanAdd;
                pi.ListCanRemove = la.CanRemove;
                pi.ListMaximumNumberOfItems = la.MaximumNumberOfItems;
            }

            var sia = pi.GetAttribute<SortIndexAttribute>();
            if (sia != null)
            {
                pi.SortIndex = sia.SortIndex;
            }

            var eba = pi.GetAttribute<EnableByAttribute>();
            if (eba != null)
            {
                pi.IsEnabledDescriptor = properties.Find(eba.PropertyName, false);
            }

            var vba = pi.GetAttribute<VisibleByAttribute>();
            if (vba != null)
            {
                pi.IsVisibleDescriptor = properties.Find(vba.PropertyName, false);
            }

            if (pi.Is(typeof(IList)))
            {
                pi.MinimumHeight = 100;
                pi.MaximumHeight = 240;
                pi.HeaderPlacement = HeaderPlacement.Above;
            }

            pi.IsOptional = pi.OptionalDescriptor != null;

            var oa = pi.GetAttribute<OptionalAttribute>();
            if (oa != null)
            {
                if (oa.PropertyName != null)
                {
                    pi.OptionalDescriptor = properties.Find(oa.PropertyName, false);
                }

                pi.IsOptional = true;
            }

            pi.IsComment = pi.GetAttribute<CommentAttribute>() != null;
            if (pi.IsComment)
            {
                pi.HeaderPlacement = HeaderPlacement.Hidden;
            }

            pi.IsEditable = pi.GetAttribute<IsEditableAttribute>() != null;

            pi.AutoUpdateText = pi.GetAttribute<AutoUpdateTextAttribute>() != null;

            var ispa = pi.GetAttribute<ItemsSourcePropertyAttribute>();
            if (ispa != null)
            {
                pi.ItemsSourceDescriptor = properties.Find(ispa.PropertyName, false);
            }

            var rpa = pi.GetAttribute<BasePathPropertyAttribute>();
            if (rpa != null)
            {
                pi.RelativePathDescriptor = properties.Find(rpa.BasePathPropertyName, false);
            }

            var fa = pi.GetAttribute<FilterPropertyAttribute>();
            if (fa != null)
            {
                pi.FilterDescriptor = properties.Find(fa.PropertyName, false);
            }

            var fsa = pi.GetAttribute<FormatStringAttribute>();
            if (fsa != null)
            {
                pi.FormatString = fsa.FormatString;
            }

            var coa = pi.GetAttribute<ConverterAttribute>();
            if (coa != null)
            {
                pi.Converter = Activator.CreateInstance(coa.ConverterType) as IValueConverter;
            }

            var sa = pi.GetAttribute<SlidableAttribute>();
            if (sa != null)
            {
                pi.IsSlidable = true;
                pi.SliderMinimum = sa.Minimum;
                pi.SliderMaximum = sa.Maximum;
                pi.SliderSmallChange = sa.SmallChange;
                pi.SliderLargeChange = sa.LargeChange;
                pi.SliderSnapToTicks = sa.SnapToTicks;
                pi.SliderTickFrequency = sa.TickFrequency;
            }

            var spa = pi.GetAttribute<SpinnableAttribute>();
            if (spa != null)
            {
                pi.IsSpinnable = true;
                pi.SpinMinimum = spa.Minimum;
                pi.SpinMaximum = spa.Maximum;
                pi.SpinSmallChange = spa.SmallChange;
                pi.SpinLargeChange = spa.LargeChange;
            }

            var wpa = pi.GetAttribute<WidePropertyAttribute>();
            if (wpa != null)
            {
                pi.HeaderPlacement = wpa.ShowHeader ? HeaderPlacement.Above : HeaderPlacement.Hidden;
            }

            var wia = pi.GetAttribute<WidthAttribute>();
            if (wia != null)
            {
                pi.Width = wia.Width;
            }

            var hpa = pi.GetAttribute<HeaderPlacementAttribute>();
            if (hpa != null)
            {
                pi.HeaderPlacement = hpa.HeaderPlacement;
            }

            var ha = pi.GetAttribute<HeightAttribute>();
            if (ha != null)
            {
                pi.Height = ha.Height;
                pi.MinimumHeight = ha.MinimumHeight;
                pi.MaximumHeight = ha.MaximumHeight;
                pi.AcceptsReturn = true;
            }
        }
Ejemplo n.º 9
0
    public static PropertyEditor GetEditor(PropertyGridLabel label, PropertyItem propertyItem) {
      if (propertyItem == null) throw new ArgumentNullException("propertyItem");

      PropertyEditor v_editor = null;
      EditorAttribute attribute = propertyItem.GetAttribute<EditorAttribute>();
      if (attribute != null) {
        ConstructorInfo ci = attribute.EditorType.GetConstructor(new Type[] { typeof(PropertyGridLabel), typeof(PropertyItem) });
        v_editor = ci.Invoke(new Object[] { label, propertyItem }) as PropertyEditor;
      }

      if (v_editor == null) {
        Type propertyType = propertyItem.PropertyType;
        v_editor = _getEditorByType(propertyType, label, propertyItem);
        while (v_editor == null && propertyType.BaseType != null) {
          propertyType = propertyType.BaseType;
          v_editor = _getEditorByType(propertyType, label, propertyItem);
        }
      }
      return v_editor;
    }
        /// <summary>
        /// Sets the properties.
        /// </summary>
        /// <param name="pi">The property item.</param>
        /// <param name="instance">The instance.</param>
        protected virtual void SetProperties(PropertyItem pi, object instance)
        {
            var tabName = this.DefaultTabName ?? instance.GetType().Name;
            var categoryName = this.DefaultCategoryName;

            // find the declaring type
            var declaringType = pi.Descriptor.ComponentType;
            var propertyInfo = instance.GetType().GetProperty(pi.Descriptor.Name);
            if (propertyInfo != null)
            {
                declaringType = propertyInfo.DeclaringType;
            }

            if (declaringType != this.CurrentDeclaringType)
            {
                this.CurrentCategory = null;
            }

            this.CurrentDeclaringType = declaringType;

            if (!this.InheritCategories)
            {
                this.CurrentCategory = null;
            }

            var ca = pi.GetAttribute<System.ComponentModel.CategoryAttribute>();
            if (ca != null)
            {
                this.CurrentCategory = ca.Category;
                this.CurrentCategoryDeclaringType = declaringType;
            }

            var ca2 = pi.GetAttribute<DataAnnotations.CategoryAttribute>();
            if (ca2 != null)
            {
                this.CurrentCategory = ca2.Category;
                this.CurrentCategoryDeclaringType = declaringType;
            }

            var category = this.CurrentCategory ?? (this.DefaultCategoryName ?? this.GetCategory(pi.Descriptor, declaringType));

            if (category != null)
            {
                var items = category.Split('|');
                if (items.Length == 2)
                {
                    tabName = items[0];
                    categoryName = items[1];
                }

                if (items.Length == 1)
                {
                    categoryName = items[0];
                }
            }

            var displayName = this.GetDisplayName(pi.Descriptor, declaringType);
            var description = this.GetDescription(pi.Descriptor, declaringType);

            // Localize the strings
            pi.DisplayName = this.GetLocalizedString(displayName, declaringType);
            pi.Description = this.GetLocalizedDescription(description, declaringType);
            pi.Category = this.GetLocalizedString(categoryName, this.CurrentCategoryDeclaringType);
            pi.Tab = this.GetLocalizedString(tabName, this.CurrentCategoryDeclaringType);

            pi.IsReadOnly = pi.Descriptor.IsReadOnly();

            // Find descriptors by convention
            pi.IsEnabledDescriptor = pi.GetDescriptor(string.Format(this.EnabledPattern, pi.PropertyName));
            var isVisibleDescriptor = pi.GetDescriptor(string.Format(this.VisiblePattern, pi.PropertyName));
            if (isVisibleDescriptor != null)
            {
                pi.IsVisibleDescriptor = isVisibleDescriptor;
                pi.IsVisibleValue = true;
            }

            pi.OptionalDescriptor = pi.GetDescriptor(string.Format(this.OptionalPattern, pi.PropertyName));

            foreach (Attribute attribute in pi.Descriptor.Attributes)
            {
                this.SetAttribute(attribute, pi, instance);
            }

            pi.IsOptional = pi.IsOptional || pi.OptionalDescriptor != null;

            if (pi.Descriptor.PropertyType == typeof(TimeSpan) && pi.Converter == null)
            {
                pi.Converter = new TimeSpanToStringConverter();
                pi.ConverterParameter = pi.FormatString;
            }
        }