Class MarkupPropertyAdapter
Routes a PropertyGrid's edits of one markup element into its DesignDocument, so they're undoable and saved.
public sealed class MarkupPropertyAdapter : PropertyGridValueAdapter
- Inheritance
-
MarkupPropertyAdapter
- Inherited Members
- Extension Methods
Remarks
- Values are read from the live object, so styles, bindings and defaults show what's on screen.
- A typed edit formats the value with MarkupValueFormatter and sets the attribute. Quick successive edits of one property coalesce into one undo step. A value with no markup form is refused, and LastError says why.
-
An attribute holding a markup extension (
{Binding …},{StaticResource …}) is shown and edited as text, so a typed editor never replaces it. - Reset removes the attribute, letting the style or default value apply again.
Constructors
MarkupPropertyAdapter(DesignDocument, NodeId, MarkupValueFormatter)
Initializes a new instance of the MarkupPropertyAdapter class.
public MarkupPropertyAdapter(DesignDocument document, NodeId node, MarkupValueFormatter formatter)
Parameters
documentDesignDocumentThe document the element belongs to.
nodeNodeIdThe element.
formatterMarkupValueFormatterFormats typed values as attribute text.
Exceptions
- ArgumentNullException
documentorformatteris null.
Properties
LastError
Gets why the last write was refused, or null when it succeeded.
public string? LastError { get; }
Property Value
Methods
CanReset(PropertyGridEntry, object)
Determines whether the row shows a Reset button.
public override bool CanReset(PropertyGridEntry entry, object target)
Parameters
entryPropertyGridEntryThe row's property.
targetobjectThe 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 override string? GetExpression(PropertyGridEntry entry, object target)
Parameters
entryPropertyGridEntryThe row's property.
targetobjectThe 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.
Reset(PropertyGridEntry, object)
Resets the property when the user presses the row's Reset button.
public override void Reset(PropertyGridEntry entry, object target)
Parameters
entryPropertyGridEntryThe row's property.
targetobjectThe object the grid shows.
Remarks
The default writes DefaultValue through TrySetValue(PropertyGridEntry, object, object?).
TrySetExpression(PropertyGridEntry, object, string)
Writes the text the user entered in an expression row.
public override bool TrySetExpression(PropertyGridEntry entry, object target, string text)
Parameters
entryPropertyGridEntryThe row's property.
targetobjectThe object the grid shows.
textstringThe entered text.
Returns
TrySetValue(PropertyGridEntry, object, object?)
Writes a value the user entered in entry's typed editor.
public override bool TrySetValue(PropertyGridEntry entry, object target, object? value)
Parameters
entryPropertyGridEntryThe row's property.
targetobjectThe object the grid shows.
valueobjectThe new value, already converted to PropertyType.