In This Article

PropertyModel Class

Represents a property grid property IDataModel that can be easily explicitly-defined and optionally bound to in XAML.

public class PropertyModel : FrameworkElement, IPropertyModel, IDataModel, IDisposable
Inheritance:
object Visual UIElement FrameworkElement object
Implements:
IPropertyModel IDataModel IDisposable

Remarks

This class only inherits FrameworkElement to support XAML data binding, since deriving lower-level classes like System.Windows.DependencyObject trigger a Cannot find governing FrameworkElement or FrameworkContentElement for target element. error when attempting to bind to its properties unless a binding proxy object is used. None of the inherited FrameworkElement members, such as those related to input, are used in any way.

Constructors

PropertyModel()

Initializes an instance of the class.

public PropertyModel()

Properties

AddChildCommand

The ICommand used to add a new child into to an associated collection/parent.

public ICommand AddChildCommand { get; }

Property Value

ICommand

CanAddChild

Indicates whether a new child can be added to an associated collection/parent.

public virtual bool CanAddChild { get; }

Property Value

bool:

true if a new child can be added to an associated collection/parent; otherwise, false.

CanAutoConfigure

Indicates whether the property can be auto-configured based on a simple Binding on its Value property.

public bool CanAutoConfigure { get; set; }

Property Value

bool:

true if the property can be auto-configured based on a simple Binding on its Value property; otherwise, false. The default value is false.

CanAutoDispose

Indicates whether the data model should be automatically disposed when it is removed from a parent data model.

public bool CanAutoDispose { get; }

Property Value

bool:

true if the data model should be automatically disposed when it is removed from a parent data model; otherwise, false.

CanRemove

Indicates whether the property can be removed from an associated collection/parent.

public virtual bool CanRemove { get; }

Property Value

bool:

true if the property can be removed from an associated collection/parent; otherwise, false.

CanResetValue

Indicates whether the property can be reset to its default value.

public bool CanResetValue { get; set; }

Property Value

bool:

true if the property can be reset to its default value; otherwise, false.

Category

Gets a category for the property.

public string? Category { get; set; }

Property Value

string:

A category for the property.

Children

The collection of child data models.

public DataModelCollection Children { get; }

Property Value

DataModelCollection

Converter

The TypeConverter to use for the property.

public TypeConverter? Converter { get; set; }

Property Value

TypeConverter

DefaultValue

The default value to use for a reset operation.

public object? DefaultValue { get; set; }

Property Value

object

Description

The description of the data model, often displayed in a summary area or a tooltip.

public string? Description { get; set; }

Property Value

string

DisplayName

The name to use when displaying the data model, often the same as Name.

public string? DisplayName { get; set; }

Property Value

string

HasStandardValues

Indicates whether the property supports StandardValues.

public virtual bool HasStandardValues { get; }

Property Value

bool:

true if the property supports StandardValues; otherwise, false.

IsExpanded

Indicates whether the data model is expanded.

public bool IsExpanded { get; set; }

Property Value

bool:

true if the data model is expanded; otherwise, false.

IsHostReadOnly

Indicates whether the host UI control (e.g., a property grid) is read-only.

public bool IsHostReadOnly { get; set; }

Property Value

bool:

true if the host UI control (e.g., a property grid) is read-only; otherwise, false.

IsImmutable

Indicates whether the Value's child properties, if any, are capable of being edited.

public bool IsImmutable { get; set; }

Property Value

bool:

true if the Value's child properties, if any, are capable of being edited; otherwise, false.

IsLimitedToStandardValues

Indicates whether the Value property can only be set to one of the values defined by the StandardValues property.

public bool IsLimitedToStandardValues { get; set; }

Property Value

bool:

true if the Value property can only be set to one of the values defined by the StandardValues property; otherwise, false.

IsMergeable

Indicates whether the property can be merged when presenting multiple objects.

public virtual bool IsMergeable { get; }

Property Value

bool:

true if the property can be merged when presenting multiple objects; otherwise, false.

IsModified

Indicates whether the data model has been modified.

public bool IsModified { get; set; }

Property Value

bool:

true if the data model has been modified; otherwise, false.

IsReadOnly

Indicates whether UI for editing the property value is read-only.

public bool IsReadOnly { get; }

Property Value

bool:

true if the UI for editing the property value is read-only; otherwise, false.

Remarks

This property is a resolved value of IsHostReadOnly and IsValueReadOnly.

IsRoot

Indicates whether the data model is the root.

protected virtual bool IsRoot { get; }

Property Value

bool:

true if the data model is the root; otherwise, false.

IsSelected

Indicates whether the data model is selected.

public bool IsSelected { get; set; }

Property Value

bool:

true if the data model is selected; otherwise, false.

IsValueReadOnly

Indicates whether the Value property is read-only.

public bool IsValueReadOnly { get; set; }

Property Value

bool:

true if the Value property is read-only; otherwise, false.

Remarks

This property can be set to true to force a normally-editable property to be read-only. Some implementations of this property will always return true when the underlying property value is unable to be set.

NamePropertyEditor

The PropertyEditor, if any, that was used to select the DataTemplate for showing the property display name.

public PropertyEditor? NamePropertyEditor { get; set; }

Property Value

PropertyEditor

NameTemplate

The DataTemplate to use for showing the property display name.

public DataTemplate? NameTemplate { get; set; }

Property Value

DataTemplate

Remarks

The priority order of value template specification is NameTemplate, NameTemplateSelector, NameTemplateKey, and finally any name templates in matching property editors.

NameTemplateKey

The resource key that references a DataTemplate to use for showing the property display name.

public object? NameTemplateKey { get; set; }

Property Value

object

Remarks

The priority order of value template specification is NameTemplate, NameTemplateSelector, NameTemplateKey, and finally any name templates in matching property editors.

NameTemplateSelector

The DataTemplateSelector to use for showing the property display name.

public DataTemplateSelector? NameTemplateSelector { get; set; }

Property Value

DataTemplateSelector

Remarks

The priority order of value template specification is NameTemplate, NameTemplateSelector, NameTemplateKey, and finally any name templates in matching property editors.

RemoveCommand

The ICommand used to remove the property from an associated collection/parent.

public ICommand RemoveCommand { get; }

Property Value

ICommand

ResetValueCommand

The ICommand used to reset the property value to its default value.

public ICommand ResetValueCommand { get; }

Property Value

ICommand

ShouldNotifyParentOnValueChange

Indicates whether the property should notify its parent property when the Value changes.

public virtual bool ShouldNotifyParentOnValueChange { get; }

Property Value

bool:

true if the property should notify its parent property when the Value changes; otherwise, false.

SortComparer

The DataModelSortComparer to use for sorting this data model's children.

public DataModelSortComparer? SortComparer { get; set; }

Property Value

DataModelSortComparer

Remarks

If this property doesn't return anything, the default SortComparer will be used.

SortImportance

A DataModelSortImportance that indicates the sort importance of this data model.

public virtual DataModelSortImportance SortImportance { get; set; }

Property Value

DataModelSortImportance

SortOrder

A numeric sort order for sorting the data model within other data models of the same sort importance.

public int SortOrder { get; set; }

Property Value

int

StandardValues

The standard list of values for the Value property.

public IEnumerable? StandardValues { get; set; }

Property Value

IEnumerable

StandardValuesAsStrings

The standard list of values for the ValueAsString property as a list of strings.

public IEnumerable<string>? StandardValuesAsStrings { get; set; }

Property Value

IEnumerable<string>

StandardValuesDisplayMemberPath

The display member path for StandardValues when IsLimitedToStandardValues is true.

public string? StandardValuesDisplayMemberPath { get; set; }

Property Value

string

StandardValuesSelectedValuePath

The selected value path for StandardValues when IsLimitedToStandardValues is true.

public string? StandardValuesSelectedValuePath { get; set; }

Property Value

string

Target

The target object that owns the property.

public object? Target { get; set; }

Property Value

object

TargetType

The Type of the Target property.

public Type TargetType { get; set; }

Property Value

Type

Value

The property value.

public object? Value { get; set; }

Property Value

object

ValueAsString

The property value in a string representation.

public string? ValueAsString { get; set; }

Property Value

string

ValuePropertyEditor

The PropertyEditor, if any, that was used to select the DataTemplate for editing the property value.

public PropertyEditor? ValuePropertyEditor { get; set; }

Property Value

PropertyEditor

ValueTemplate

The DataTemplate to use for editing the property value.

public DataTemplate? ValueTemplate { get; set; }

Property Value

DataTemplate

Remarks

The priority order of value template specification is ValueTemplate, ValueTemplateSelector, ValueTemplateKey, ValueTemplateKind, and finally any value templates in matching property editors.

ValueTemplateKey

The resource key that references a DataTemplate to use for editing the property value.

public object? ValueTemplateKey { get; set; }

Property Value

object

Remarks

The priority order of value template specification is ValueTemplate, ValueTemplateSelector, ValueTemplateKey, ValueTemplateKind, and finally any value templates in matching property editors.

ValueTemplateKind

The DefaultValueTemplateKind that specifies a default value cell template to use for editing the property value.

public DefaultValueTemplateKind ValueTemplateKind { get; set; }

Property Value

DefaultValueTemplateKind

Remarks

The priority order of value template specification is ValueTemplate, ValueTemplateSelector, ValueTemplateKey, ValueTemplateKind, and finally any value templates in matching property editors.

ValueTemplateSelector

The DataTemplateSelector to use for editing the property value.

public DataTemplateSelector? ValueTemplateSelector { get; set; }

Property Value

DataTemplateSelector

Remarks

The priority order of value template specification is ValueTemplate, ValueTemplateSelector, ValueTemplateKey, ValueTemplateKind, and finally any value templates in matching property editors.

ValueType

The Type of the Value property.

public Type? ValueType { get; set; }

Property Value

Type

Values

The property values, of which there will only be more than one if this is a merged property.

public virtual IList<object?>? Values { get; }

Property Value

IList<object>

Methods

AddChild()

Adds a new child into to an associated collection/parent.

public virtual void AddChild()

ConvertFromString(string?)

Converts the specified value from a string.

protected virtual object? ConvertFromString(string? stringValue)
Parameter Type Description
stringValue string

The string value to convert.

Returns

object:

An object from the string representation, or null.

ConvertToString(object?)

Converts the specified value to a string.

protected virtual string? ConvertToString(object? value)
Parameter Type Description
value object

The value to convert.

Returns

string:

A string representation of the specified value, or null.

CycleToNextStandardValue()

Cycles the property value to the next standard value.

public virtual bool CycleToNextStandardValue()

Returns

bool:

true if a standard value was set; otherwise, false.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by the object and optionally releases the managed resources.

protected virtual void Dispose(bool disposing)
Parameter Type Description
disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks

This method is called by the public Dispose method and the Finalize method. Dispose invokes this method with the disposing parameter set to true. Finalize invokes this method with disposing set to false.

GetErrorMessages(string?)

Returns the error messages for the target object or one of its properties.

protected virtual IEnumerable GetErrorMessages(string? columnName)
Parameter Type Description
columnName string

The name of the property to examine, or null if the target object itself should be examined.

Returns

IEnumerable:

The error messages that are applicable, if any.

NotifyPropertyChanged(string)

Notifies that a property has changed.

[Obsolete("Use one of the new SetProperty or OnPropertyChanged methods instead of this deprecated NotifyPropertyChanged method.", false)]
protected void NotifyPropertyChanged(string propertyName)
Parameter Type Description
propertyName string

The name of the property that was changed.

OnPropertyChanged(PropertyChangedEventArgs)

Raises the PropertyChanged event.

protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
Parameter Type Description
e PropertyChangedEventArgs

The event data.

OnPropertyChanged(string?)

Raises the PropertyChanged event.

protected void OnPropertyChanged(string? propertyName = null)
Parameter Type Description
propertyName string

(Optional) The name of the property that changed.

RaiseChildPropertyAddedEvent(PropertyModelChildChangeEventArgs)

Raises a collection item property added event on the PropertyGrid.

protected void RaiseChildPropertyAddedEvent(PropertyModelChildChangeEventArgs e)
Parameter Type Description
e PropertyModelChildChangeEventArgs

The event data.

RaiseChildPropertyAddingEvent(PropertyModelChildChangeEventArgs)

Raises a collection item property adding event on the PropertyGrid.

protected void RaiseChildPropertyAddingEvent(PropertyModelChildChangeEventArgs e)
Parameter Type Description
e PropertyModelChildChangeEventArgs

The event data.

RaiseChildPropertyRemovedEvent(PropertyModelChildChangeEventArgs)

Raises a collection item property removed event on the PropertyGrid.

protected void RaiseChildPropertyRemovedEvent(PropertyModelChildChangeEventArgs e)
Parameter Type Description
e PropertyModelChildChangeEventArgs

The event data.

RaiseChildPropertyRemovingEvent(PropertyModelChildChangeEventArgs)

Raises a collection item property removing event on the PropertyGrid.

protected void RaiseChildPropertyRemovingEvent(PropertyModelChildChangeEventArgs e)
Parameter Type Description
e PropertyModelChildChangeEventArgs

The event data.

RaisePropertyValueChangedEvent(PropertyModelValueChangeEventArgs)

Raises a property value changed event on the PropertyGrid.

protected void RaisePropertyValueChangedEvent(PropertyModelValueChangeEventArgs e)
Parameter Type Description
e PropertyModelValueChangeEventArgs

The event data.

RaisePropertyValueChangingEvent(PropertyModelValueChangeEventArgs)

Raises a property value changing event on the PropertyGrid.

protected void RaisePropertyValueChangingEvent(PropertyModelValueChangeEventArgs e)
Parameter Type Description
e PropertyModelValueChangeEventArgs

The event data.

Refresh(PropertyRefreshReason)

Refreshes the property based on the specified reason.

public virtual void Refresh(PropertyRefreshReason reason)
Parameter Type Description
reason PropertyRefreshReason

The reason the property needs to be refreshed.

RefreshChildren()

Refreshes the contents of the Children property.

protected virtual void RefreshChildren()

Remove()

Removes the property from an associated collection/parent.

public virtual void Remove()

ResetValue()

Resets the property value to its default value.

public virtual void ResetValue()

SetProperty<T>(ref T, T, string?)

Called from a property setter to change the backing field's value and raise PropertyChanged notification events if the new value is not equal to the current value.

protected bool SetProperty<T>(ref T field, T newValue, string? propertyName = null)
Type Parameters:
T -

The type of the property that changed.

Parameter Type Description
field T

The backing field that holds the property's value, which may be updated.

newValue T

The new property value.

propertyName string

(Optional) The name of the property that changed.

Returns

bool:

true if the property was changed; otherwise, false.

ToString()

Returns the string representation of this object.

public override string ToString()

Returns

string:

The string representation of this object.

Events

PropertyChanged

Occurs when a property value changes.

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler

Fields

CanAutoConfigureProperty

Defines the CanAutoConfigure property.

public static readonly DependencyProperty CanAutoConfigureProperty

CanResetValueProperty

Defines the CanResetValue property.

public static readonly DependencyProperty CanResetValueProperty

CategoryProperty

Defines the Category property.

public static readonly DependencyProperty CategoryProperty

ConverterProperty

Defines the Converter property.

public static readonly DependencyProperty ConverterProperty

DefaultValueProperty

Defines the DefaultValue property.

public static readonly DependencyProperty DefaultValueProperty

DescriptionProperty

Defines the Description property.

public static readonly DependencyProperty DescriptionProperty

DisplayNameProperty

Defines the DisplayName property.

public static readonly DependencyProperty DisplayNameProperty

IsExpandedProperty

Defines the IsExpanded property.

public static readonly DependencyProperty IsExpandedProperty

IsHostReadOnlyProperty

Defines the IsHostReadOnly property.

public static readonly DependencyProperty IsHostReadOnlyProperty

IsImmutableProperty

Defines the IsImmutable property.

public static readonly DependencyProperty IsImmutableProperty

IsLimitedToStandardValuesProperty

Defines the IsLimitedToStandardValues property.

public static readonly DependencyProperty IsLimitedToStandardValuesProperty

IsModifiedProperty

Defines the IsModified property.

public static readonly DependencyProperty IsModifiedProperty

IsReadOnlyProperty

Defines the IsReadOnly property.

public static readonly DependencyProperty IsReadOnlyProperty

IsSelectedProperty

Defines the IsSelected property.

public static readonly DependencyProperty IsSelectedProperty

IsValueReadOnlyProperty

Defines the IsValueReadOnly property.

public static readonly DependencyProperty IsValueReadOnlyProperty

NamePropertyEditorProperty

Defines the NamePropertyEditor property.

public static readonly DependencyProperty NamePropertyEditorProperty

NameTemplateKeyProperty

Defines the NameTemplateKey property.

public static readonly DependencyProperty NameTemplateKeyProperty

NameTemplateProperty

Defines the NameTemplate property.

public static readonly DependencyProperty NameTemplateProperty

NameTemplateSelectorProperty

Defines the NameTemplateSelector property.

public static readonly DependencyProperty NameTemplateSelectorProperty

SortComparerProperty

Defines the SortComparer property.

public static readonly DependencyProperty SortComparerProperty

SortImportanceProperty

Defines the SortImportance property.

public static readonly DependencyProperty SortImportanceProperty

SortOrderProperty

Defines the SortOrder property.

public static readonly DependencyProperty SortOrderProperty

StandardValuesAsStringsProperty

Defines the StandardValuesAsStrings property.

public static readonly DependencyProperty StandardValuesAsStringsProperty

StandardValuesDisplayMemberPathProperty

Defines the StandardValuesDisplayMemberPath property.

public static readonly DependencyProperty StandardValuesDisplayMemberPathProperty

StandardValuesProperty

Defines the StandardValues property.

public static readonly DependencyProperty StandardValuesProperty

StandardValuesSelectedValuePathProperty

Defines the StandardValuesSelectedValuePath property.

public static readonly DependencyProperty StandardValuesSelectedValuePathProperty

TargetProperty

Defines the Target property.

public static readonly DependencyProperty TargetProperty

TargetTypeProperty

Defines the TargetType property.

public static readonly DependencyProperty TargetTypeProperty

ValueProperty

Defines the Value property.

public static readonly DependencyProperty ValueProperty

ValuePropertyEditorProperty

Defines the ValuePropertyEditor property.

public static readonly DependencyProperty ValuePropertyEditorProperty

ValueTemplateKeyProperty

Defines the ValueTemplateKey property.

public static readonly DependencyProperty ValueTemplateKeyProperty

ValueTemplateKindProperty

Defines the ValueTemplateKind property.

public static readonly DependencyProperty ValueTemplateKindProperty

ValueTemplateProperty

Defines the ValueTemplate property.

public static readonly DependencyProperty ValueTemplateProperty

ValueTemplateSelectorProperty

Defines the ValueTemplateSelector property.

public static readonly DependencyProperty ValueTemplateSelectorProperty

ValueTypeProperty

Defines the ValueType property.

public static readonly DependencyProperty ValueTypeProperty

Extension Methods