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

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

public ICommand AddChildCommand { get; }

Property Value

ICommand:

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

CanAddChild

Gets 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

Gets or sets 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

Gets 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

Gets 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

Gets or sets 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. The default value is false.

Category

Gets or sets a category for the property.

public string Category { get; set; }

Property Value

string:

A category for the property.

Children

Gets the collection of child data models.

public DataModelCollection Children { get; }

Property Value

DataModelCollection:

The collection of child data models.

Converter

Gets or sets the TypeConverter to use for the property.

public TypeConverter Converter { get; set; }

Property Value

TypeConverter:

The TypeConverter to use for the property.

DefaultValue

Gets or sets the default value to use for a reset operation.

public object DefaultValue { get; set; }

Property Value

object:

The default value to use for a reset operation.

Description

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

public string Description { get; set; }

Property Value

string:

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

DisplayName

Gets or sets the name to use when displaying the data model, often the same as Name.

public string DisplayName { get; set; }

Property Value

string:

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

HasStandardValues

Gets whether the property supports StandardValues.

public virtual bool HasStandardValues { get; }

Property Value

bool:

true if the property supports StandardValues; otherwise, false.

IsExpanded

Gets or sets whether the data model is expanded.

public bool IsExpanded { get; set; }

Property Value

bool:

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

IsHostReadOnly

Gets or sets 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

Gets 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

Gets or sets 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

Gets 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

Gets or sets 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

Gets 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, and also considers whether a parent property is immutable.

IsRoot

Gets 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

Gets or sets whether the data model is selected.

public bool IsSelected { get; set; }

Property Value

bool:

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

IsValueReadOnly

Gets or sets 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.

NamePropertyEditor

Gets or sets 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:

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

NameTemplate

Gets or sets the DataTemplate to use for showing the property display name.

public DataTemplate NameTemplate { get; set; }

Property Value

DataTemplate:

The DataTemplate to use for showing the property display name.

Remarks

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

NameTemplateKey

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

public object NameTemplateKey { get; set; }

Property Value

object:

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

Remarks

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

NameTemplateSelector

Gets or sets the DataTemplateSelector to use for showing the property display name.

public DataTemplateSelector NameTemplateSelector { get; set; }

Property Value

DataTemplateSelector:

The DataTemplateSelector to use for showing the property display name.

Remarks

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

RemoveCommand

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

public ICommand RemoveCommand { get; }

Property Value

ICommand:

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

ResetValueCommand

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

public ICommand ResetValueCommand { get; }

Property Value

ICommand:

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

ShouldNotifyParentOnValueChange

Gets 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

Gets or sets the DataModelSortComparer to use for sorting this data model's children.

public DataModelSortComparer SortComparer { get; set; }

Property Value

DataModelSortComparer:

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

Remarks

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

SortImportance

Gets or sets a DataModelSortImportance that indicates the sort importance of this data model.

public virtual DataModelSortImportance SortImportance { get; set; }

Property Value

DataModelSortImportance:

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

SortOrder

Gets or sets 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:

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

StandardValues

Gets or sets the standard list of values for the Value property.

public IEnumerable StandardValues { get; set; }

Property Value

IEnumerable:

The standard list of values for the Value property.

StandardValuesAsStrings

Gets or sets the standard list of values for the ValueAsString property as a list of strings.

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

Property Value

IEnumerable<string>:

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

StandardValuesDisplayMemberPath

Gets or sets the display member path for StandardValues when IsLimitedToStandardValues is true.

public string StandardValuesDisplayMemberPath { get; set; }

Property Value

string:

The display member path for StandardValues when IsLimitedToStandardValues is true.

StandardValuesSelectedValuePath

Gets or sets the selected value path for StandardValues when IsLimitedToStandardValues is true.

public string StandardValuesSelectedValuePath { get; set; }

Property Value

string:

The selected value path for StandardValues when IsLimitedToStandardValues is true.

Target

Gets or sets the target object that owns the property.

public object Target { get; set; }

Property Value

object:

The target object that owns the property.

TargetType

Gets or sets the Type of the Target property.

public Type TargetType { get; set; }

Property Value

Type:

The Type of the Target property.

Value

Gets or sets the property value.

public object Value { get; set; }

Property Value

object:

The property value.

ValueAsString

Gets or sets the property value in a string representation.

public string ValueAsString { get; set; }

Property Value

string:

The property value in a string representation.

ValuePropertyEditor

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

public PropertyEditor ValuePropertyEditor { get; set; }

Property Value

PropertyEditor:

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

ValueTemplate

Gets or sets the DataTemplate to use for editing the property value.

public DataTemplate ValueTemplate { get; set; }

Property Value

DataTemplate:

The DataTemplate to use for editing the property value.

Remarks

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

ValueTemplateKey

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

public object ValueTemplateKey { get; set; }

Property Value

object:

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

Remarks

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

ValueTemplateKind

Gets or sets the DefaultValueTemplateKind that specifies a default value cell template to use for editing the property value.

public DefaultValueTemplateKind ValueTemplateKind { get; set; }

Property Value

DefaultValueTemplateKind:

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

Remarks

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

ValueTemplateSelector

Gets or sets the DataTemplateSelector to use for editing the property value.

public DataTemplateSelector ValueTemplateSelector { get; set; }

Property Value

DataTemplateSelector:

The DataTemplate to use for editing the property value.

Remarks

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

ValueType

Gets or sets the Type of the Value property.

public Type ValueType { get; set; }

Property Value

Type:

The Type of the Value property.

Values

Gets 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>:

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

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

Releases all resources used by the object.

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.

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 PropertyChangedEventArgs that contains the event data.

RaiseChildPropertyAddedEvent(PropertyModelChildChangeEventArgs)

Raises a collection item property added event on the PropertyGrid.

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

The PropertyModelChildChangeEventArgs that contains 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 PropertyModelChildChangeEventArgs that contains 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 PropertyModelChildChangeEventArgs that contains 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 PropertyModelChildChangeEventArgs that contains 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 PropertyModelValueChangeEventArgs that contains 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 PropertyModelValueChangeEventArgs that contains 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()

ToString()

Returns a string representation of this instance.

public override string ToString()

Returns

string:

A string representation of this instance.

Events

PropertyChanged

Occurs when a property has been changed.

public event PropertyChangedEventHandler PropertyChanged

Event Type

PropertyChangedEventHandler

Fields

CanAutoConfigureProperty

Identifies the CanAutoConfigure dependency property. This field is read-only.

public static readonly DependencyProperty CanAutoConfigureProperty

CanResetValueProperty

Identifies the CanResetValue dependency property. This field is read-only.

public static readonly DependencyProperty CanResetValueProperty

CategoryProperty

Identifies the Category dependency property. This field is read-only.

public static readonly DependencyProperty CategoryProperty

ConverterProperty

Identifies the Converter dependency property. This field is read-only.

public static readonly DependencyProperty ConverterProperty

DefaultValueProperty

Identifies the DefaultValue dependency property. This field is read-only.

public static readonly DependencyProperty DefaultValueProperty

DescriptionProperty

Identifies the Description dependency property. This field is read-only.

public static readonly DependencyProperty DescriptionProperty

DisplayNameProperty

Identifies the DisplayName dependency property. This field is read-only.

public static readonly DependencyProperty DisplayNameProperty

IsExpandedProperty

Identifies the IsExpanded dependency property. This field is read-only.

public static readonly DependencyProperty IsExpandedProperty

IsHostReadOnlyProperty

Identifies the IsHostReadOnly dependency property. This field is read-only.

public static readonly DependencyProperty IsHostReadOnlyProperty

IsImmutableProperty

Identifies the IsImmutable dependency property. This field is read-only.

public static readonly DependencyProperty IsImmutableProperty

IsLimitedToStandardValuesProperty

Identifies the IsLimitedToStandardValues dependency property. This field is read-only.

public static readonly DependencyProperty IsLimitedToStandardValuesProperty

IsModifiedProperty

Identifies the IsModified dependency property. This field is read-only.

public static readonly DependencyProperty IsModifiedProperty

IsReadOnlyProperty

Identifies the IsReadOnly dependency property. This field is read-only.

public static readonly DependencyProperty IsReadOnlyProperty

IsSelectedProperty

Identifies the IsSelected dependency property. This field is read-only.

public static readonly DependencyProperty IsSelectedProperty

IsValueReadOnlyProperty

Identifies the IsValueReadOnly dependency property. This field is read-only.

public static readonly DependencyProperty IsValueReadOnlyProperty

NamePropertyEditorProperty

Identifies the NamePropertyEditor dependency property. This field is read-only.

public static readonly DependencyProperty NamePropertyEditorProperty

NameTemplateKeyProperty

Identifies the NameTemplateKey dependency property. This field is read-only.

public static readonly DependencyProperty NameTemplateKeyProperty

NameTemplateProperty

Identifies the NameTemplate dependency property. This field is read-only.

public static readonly DependencyProperty NameTemplateProperty

NameTemplateSelectorProperty

Identifies the NameTemplateSelector dependency property. This field is read-only.

public static readonly DependencyProperty NameTemplateSelectorProperty

SortComparerProperty

Identifies the SortComparer dependency property. This field is read-only.

public static readonly DependencyProperty SortComparerProperty

SortImportanceProperty

Identifies the SortImportance dependency property. This field is read-only.

public static readonly DependencyProperty SortImportanceProperty

SortOrderProperty

Identifies the SortOrder dependency property. This field is read-only.

public static readonly DependencyProperty SortOrderProperty

StandardValuesAsStringsProperty

Identifies the StandardValuesAsStrings dependency property. This field is read-only.

public static readonly DependencyProperty StandardValuesAsStringsProperty

StandardValuesDisplayMemberPathProperty

Identifies the StandardValuesDisplayMemberPath dependency property. This field is read-only.

public static readonly DependencyProperty StandardValuesDisplayMemberPathProperty

StandardValuesProperty

Identifies the StandardValues dependency property. This field is read-only.

public static readonly DependencyProperty StandardValuesProperty

StandardValuesSelectedValuePathProperty

Identifies the StandardValuesSelectedValuePath dependency property. This field is read-only.

public static readonly DependencyProperty StandardValuesSelectedValuePathProperty

TargetProperty

Identifies the Target dependency property. This field is read-only.

public static readonly DependencyProperty TargetProperty

TargetTypeProperty

Identifies the TargetType dependency property. This field is read-only.

public static readonly DependencyProperty TargetTypeProperty

ValueProperty

Identifies the Value dependency property. This field is read-only.

public static readonly DependencyProperty ValueProperty

ValuePropertyEditorProperty

Identifies the ValuePropertyEditor dependency property. This field is read-only.

public static readonly DependencyProperty ValuePropertyEditorProperty

ValueTemplateKeyProperty

Identifies the ValueTemplateKey dependency property. This field is read-only.

public static readonly DependencyProperty ValueTemplateKeyProperty

ValueTemplateKindProperty

Identifies the ValueTemplateKind dependency property. This field is read-only.

public static readonly DependencyProperty ValueTemplateKindProperty

ValueTemplateProperty

Identifies the ValueTemplate dependency property. This field is read-only.

public static readonly DependencyProperty ValueTemplateProperty

ValueTemplateSelectorProperty

Identifies the ValueTemplateSelector dependency property. This field is read-only.

public static readonly DependencyProperty ValueTemplateSelectorProperty

ValueTypeProperty

Identifies the ValueType dependency property. This field is read-only.

public static readonly DependencyProperty ValueTypeProperty