Table of Contents

Class PropertyGridValueAdapter

Namespace
Icy.Data
Assembly
IcyUI.dll

Decides how a PropertyGrid reads and writes the properties it shows.

public class PropertyGridValueAdapter
Inheritance
PropertyGridValueAdapter
Derived
Inherited Members
Extension Methods

Remarks

The default adapter (Default) reads and writes the target's properties directly. Derive from this class to route edits elsewhere, for example into an undoable document, or to show some properties as raw text expressions instead of typed editors.

Every member is virtual and has a working default, so an adapter overrides only what it changes.

The default adapter offers Reset for a property that declares a DefaultValueAttribute and currently holds another value.

Properties

Default

Gets the adapter that reads and writes properties directly through reflection.

public static PropertyGridValueAdapter Default { get; }

Property Value

PropertyGridValueAdapter

Methods

CanReset(PropertyGridEntry, object)

Determines whether the row shows a Reset button.

public virtual bool CanReset(PropertyGridEntry entry, object target)

Parameters

entry PropertyGridEntry

The row's property.

target object

The object the grid shows.

Returns

bool

The default: true when the property declares a DefaultValueAttribute, is writable, and currently holds another value.

GetExpression(PropertyGridEntry, object)

Gets the raw text to show instead of a typed editor, such as a {Binding} expression.

public virtual string? GetExpression(PropertyGridEntry entry, object target)

Parameters

entry PropertyGridEntry

The row's property.

target object

The object the grid shows.

Returns

string

The text, or null (the default) for a typed editor. A non-null text turns the row into a text box that commits through TrySetExpression(PropertyGridEntry, object, string) on Enter or when it loses focus.

GetValue(PropertyGridEntry, object)

Reads the value entry's editor shows.

public virtual object? GetValue(PropertyGridEntry entry, object target)

Parameters

entry PropertyGridEntry

The row's property.

target object

The object the grid shows.

Returns

object

The value; the default reads it with GetValue(object).

Reset(PropertyGridEntry, object)

Resets the property when the user presses the row's Reset button.

public virtual void Reset(PropertyGridEntry entry, object target)

Parameters

entry PropertyGridEntry

The row's property.

target object

The object the grid shows.

Remarks

TrySetExpression(PropertyGridEntry, object, string)

Writes the text the user entered in an expression row.

public virtual bool TrySetExpression(PropertyGridEntry entry, object target, string text)

Parameters

entry PropertyGridEntry

The row's property.

target object

The object the grid shows.

text string

The entered text.

Returns

bool

true when the text was accepted; on false (the default) the row is marked Invalid.

TrySetValue(PropertyGridEntry, object, object?)

Writes a value the user entered in entry's typed editor.

public virtual bool TrySetValue(PropertyGridEntry entry, object target, object? value)

Parameters

entry PropertyGridEntry

The row's property.

target object

The object the grid shows.

value object

The new value, already converted to PropertyType.

Returns

bool

true when the value was accepted.