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. if (pd.PropertyDescriptor.Converter is ExpandableObjectConverter) { propertyItem.IsExpandable = true; } else { 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); } } }
internal FrameworkElement GenerateChildrenEditorElement(PropertyItem propertyItem) { FrameworkElement editorElement = null; DescriptorPropertyDefinitionBase pd = propertyItem.DescriptorDefinition; object definitionKey = null; Type definitionKeyAsType = definitionKey as Type; ITypeEditor editor = null; 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); } foreach (var edef in this.PropertyContainer.EditorDefinitions.Where(x => x.HasAttribute != null)) { if (propertyItem.PropertyDescriptor.Attributes.Cast <Attribute>().Any(x => x.GetType() == edef.HasAttribute)) { return(edef.GenerateEditingElementInternal(propertyItem)); } } if (editorElement == null) { if (pd.IsReadOnly) { editor = new TextBlockEditor(); } // Fallback: Use a default type editor. if (editor == null) { editor = (definitionKeyAsType != null) ? PropertyGridUtilities.CreateDefaultEditor(definitionKeyAsType, null) : pd.CreateDefaultEditor(); } Debug.Assert(editor != null); editorElement = editor.ResolveEditor(propertyItem); } return(editorElement); }
internal PropertyItem(DescriptorPropertyDefinitionBase definition) : base() { if (definition == null) { throw new ArgumentNullException("definition"); } this.DescriptorDefinition = definition; }
internal FrameworkElement GenerateChildrenEditorElement(PropertyItem propertyItem) { FrameworkElement editorElement = null; DescriptorPropertyDefinitionBase pd = propertyItem.DescriptorDefinition; object definitionKey = null; Type definitionKeyAsType = definitionKey as Type; ITypeEditor editor = null; if (editor == null) { editor = pd.CreateAttributeEditor(); } if (editor != null) { editorElement = editor.ResolveEditor(propertyItem); } if ((editorElement == null) && (definitionKey == null) && (propertyItem.PropertyDescriptor != null)) { editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyDescriptor.Name, propertyItem); } if (editorElement == null && definitionKeyAsType == null) { editorElement = this.GenerateCustomEditingElement(propertyItem.PropertyType, propertyItem); } if (editorElement == null) { if (propertyItem.IsReadOnly && !ListUtilities.IsListOfItems(propertyItem.PropertyType) && !ListUtilities.IsCollectionOfItems(propertyItem.PropertyType) && !ListUtilities.IsDictionaryOfItems(propertyItem.PropertyType)) { editor = new TextBlockEditor((propertyItem.PropertyDescriptor != null) ? propertyItem.PropertyDescriptor.Converter : null); } // Fallback: Use a default type editor. if (editor == null) { editor = (definitionKeyAsType != null) ? PropertyGridUtilities.CreateDefaultEditor(definitionKeyAsType, null, propertyItem) : pd.CreateDefaultEditor(propertyItem); } Debug.Assert(editor != null); editorElement = editor.ResolveEditor(propertyItem); } return(editorElement); }
internal void SetRedInvalidBorder(BindingExpression be) { 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]); } } }
internal PropertyItem(DescriptorPropertyDefinitionBase definition) : base(definition.IsPropertyGridCategorized) { if (definition == null) { throw new ArgumentNullException("definition"); } this.DescriptorDefinition = definition; this.ContainerHelper = definition.CreateContainerHelper(this); definition.ContainerHelperInvalidated += new EventHandler(OnDefinitionContainerHelperInvalidated); }
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); editorElement = editor.ResolveEditor(propertyItem); } return(editorElement); }
private void Init( DescriptorPropertyDefinitionBase definition ) { if( definition == null ) throw new ArgumentNullException( "definition" ); if( this.ContainerHelper != null ) { this.ContainerHelper.ClearHelper(); } this.DescriptorDefinition = definition; this.ContainerHelper = definition.CreateContainerHelper( this ); definition.ContainerHelperInvalidated += new EventHandler( OnDefinitionContainerHelperInvalidated ); this.Loaded += this.PropertyItem_Loaded; }
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. if (pd.PropertyDescriptor.Converter is ExpandableObjectConverter) { propertyItem.IsExpandable = true; } else { 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); } } // PropertyItem.PropertyType's defaultValue equals current PropertyItem's value => set the DefaultValue attribute if (pd.DefaultValue != null) { var typeDefaultValue = this.GetTypeDefaultValue(propertyItem.PropertyType); if (((propertyItem.Value != null) && propertyItem.Value.Equals(typeDefaultValue)) || ((propertyItem.Value == null) && (typeDefaultValue == propertyItem.Value))) { #if VS2008 propertyItem.Value = pd.DefaultValue; #else propertyItem.SetCurrentValue(PropertyItem.ValueProperty, pd.DefaultValue); #endif } } }
internal void SetRedInvalidBorder(BindingExpression be) { if ((be != null) && be.DataItem is DescriptorPropertyDefinitionBase) { this.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() => { DescriptorPropertyDefinitionBase descriptor = be.DataItem as DescriptorPropertyDefinitionBase; if ((descriptor != null) && Validation.GetHasError(descriptor)) { var errors = Validation.GetErrors(descriptor); Validation.MarkInvalid(be, errors[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); }
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); }
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; } } }
internal PropertyItem(DescriptorPropertyDefinitionBase definition) : base(definition.IsPropertyGridCategorized, !definition.PropertyType.IsArray) { this.Init(definition); }
internal PropertyItem( DescriptorPropertyDefinitionBase definition ) : base() { if( definition == null ) throw new ArgumentNullException( "definition" ); this.DescriptorDefinition = definition; }
internal PropertyItem( DescriptorPropertyDefinitionBase definition ) : base( definition.IsPropertyGridCategorized ) { if( definition == null ) throw new ArgumentNullException( "definition" ); this.DescriptorDefinition = definition; this.ContainerHelper = definition.CreateContainerHelper( this ); definition.ContainerHelperInvalidated += new EventHandler( OnDefinitionContainerHelperInvalidated ); }