Exemplo n.º 1
0
        private void InitializePropertyItem(PropertyItem propertyItem)
        {
            DescriptorPropertyDefinitionBase pd = propertyItem.DescriptorDefinition;

            propertyItem.PropertyDescriptor = pd.PropertyDescriptor;

            propertyItem.IsReadOnly    = pd.IsReadOnly;
            propertyItem.DisplayName   = pd.DisplayName;
            propertyItem.Description   = pd.Description;
            propertyItem.Category      = pd.Category;
            propertyItem.PropertyOrder = pd.DisplayOrder;

            //These properties can vary with the value. They need to be bound.
            SetupDefinitionBinding(propertyItem, PropertyItemBase.IsExpandableProperty, pd, () => pd.IsExpandable, BindingMode.OneWay);
            SetupDefinitionBinding(propertyItem, PropertyItemBase.AdvancedOptionsIconProperty, pd, () => pd.AdvancedOptionsIcon, BindingMode.OneWay);
            SetupDefinitionBinding(propertyItem, PropertyItemBase.AdvancedOptionsTooltipProperty, pd, () => pd.AdvancedOptionsTooltip, BindingMode.OneWay);
            SetupDefinitionBinding(propertyItem, PropertyItem.ValueProperty, pd, () => pd.Value, BindingMode.TwoWay);

            if (pd.CommandBindings != null)
            {
                foreach (CommandBinding commandBinding in pd.CommandBindings)
                {
                    propertyItem.CommandBindings.Add(commandBinding);
                }
            }
        }
Exemplo n.º 2
0
        private FrameworkElement GenerateChildrenEditorElement(PropertyItem propertyItem)
        {
            FrameworkElement editorElement      = null;
            DescriptorPropertyDefinitionBase pd = propertyItem.DescriptorDefinition;
            object      definitionKey           = null;
            Type        definitionKeyAsType     = definitionKey as Type;
            ITypeEditor editor = null;

            if (pd.IsReadOnly)
            {
                editor = new TextBlockEditor();
            }

            if (editor == null)
            {
                editor = pd.CreateAttributeEditor();
            }

            if (editor != null)
            {
                editorElement = editor.ResolveEditor(propertyItem);
            }


            if (editorElement == null && definitionKey == null)
            {
                editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyDescriptor.Name, propertyItem);
            }

            if (editorElement == null && definitionKeyAsType == null)
            {
                editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyType, propertyItem);
            }

            if (editorElement == null)
            {
                // Fallback: Use a default type editor.
                if (editor == null)
                {
                    editor = (definitionKeyAsType != null)
                    ? PropertyGridUtilities.CreateDefaultEditor(definitionKeyAsType, null)
                    : pd.CreateDefaultEditor();
                }

                Debug.Assert(editor != null);

                if (editor != null)
                {
                    editorElement = editor.ResolveEditor(propertyItem);
                }
            }

            return(editorElement);
        }
Exemplo n.º 3
0
        internal PropertyItem(DescriptorPropertyDefinitionBase definition)
            : base()
        {
            if (definition == null)
            {
                throw new ArgumentNullException("definition");
            }

            this.DescriptorDefinition              = definition;
            this.ContainerHelper                   = definition.CreateContainerHelper(this);
            definition.ContainerHelperInvalidated += new EventHandler(OnDefinitionContainerHelperInvalidated);
        }
Exemplo n.º 4
0
        private void SetupDefinitionBinding <T>(
            PropertyItem propertyItem,
            DependencyProperty itemProperty,
            DescriptorPropertyDefinitionBase pd,
            Expression <Func <T> > definitionProperty,
            BindingMode bindingMode)
        {
            string  sourceProperty = ReflectionHelper.GetPropertyOrFieldName(definitionProperty);
            Binding binding        = new Binding(sourceProperty)
            {
                Source = pd,
                Mode   = bindingMode
            };

            propertyItem.SetBinding(itemProperty, binding);
        }
Exemplo n.º 5
0
        protected override object OnCoerceValueChanged(object baseValue)
        {
            // Propagate error from DescriptorPropertyDefinitionBase to PropertyItem.Value
            // to see the red error rectangle in the propertyGrid.
            BindingExpression be = GetBindingExpression(PropertyItem.ValueProperty);

            if ((be != null) && be.DataItem is DescriptorPropertyDefinitionBase)
            {
                DescriptorPropertyDefinitionBase descriptor = be.DataItem as DescriptorPropertyDefinitionBase;
                if (Validation.GetHasError(descriptor))
                {
                    ReadOnlyObservableCollection <ValidationError> errors = Validation.GetErrors(descriptor);
                    Validation.MarkInvalid(be, errors[0]);
                }
            }
            return(baseValue);
        }
Exemplo n.º 6
0
        internal void InitializeDescriptorDefinition(
            DescriptorPropertyDefinitionBase descriptorDef,
            PropertyDefinition propertyDefinition)
        {
            if (descriptorDef == null)
            {
                throw new ArgumentNullException("descriptorDef");
            }

            if (propertyDefinition == null)
            {
                return;
            }

            // Values defined on PropertyDefinition have priority on the attributes
            if (propertyDefinition != null)
            {
                if (propertyDefinition.Category != null)
                {
                    descriptorDef.Category      = propertyDefinition.Category;
                    descriptorDef.CategoryValue = propertyDefinition.Category;
                }

                if (propertyDefinition.Description != null)
                {
                    descriptorDef.Description = propertyDefinition.Description;
                }

                if (propertyDefinition.DisplayName != null)
                {
                    descriptorDef.DisplayName = propertyDefinition.DisplayName;
                }

                if (propertyDefinition.DisplayOrder != null)
                {
                    descriptorDef.DisplayOrder = propertyDefinition.DisplayOrder.Value;
                }

                if (propertyDefinition.IsExpandable != null)
                {
                    descriptorDef.ExpandableAttribute = propertyDefinition.IsExpandable.Value;
                }
            }
        }