Table of Contents

Class MarkupEditor

Namespace
Icy.Design
Assembly
IcyUI.Design.dll

Edits a DesignDocument: every edit changes the markup text minimally and is mirrored onto every live page built from it.

public sealed class MarkupEditor
Inheritance
MarkupEditor
Inherited Members
Extension Methods

Remarks

Every edit is all-or-nothing. When it can't be made, or the live page rejects it (a value that doesn't convert, say), the method returns a failed EditResult and neither the text nor any page changed.

Edits to opaque parts of the markup (styles, resources, templates, anything under a property element such as <Grid.RowDefinitions>) change the text only, and set NeedsReload.

Call the editor on the thread that owns the document's pages; other threads get an InvalidOperationException.

Properties

Document

Gets the document this editor changes.

public DesignDocument Document { get; }

Property Value

DesignDocument

UndoStack

Gets the undo and redo history of this editor's edits.

public UndoStack UndoStack { get; }

Property Value

UndoStack

Methods

BeginTransaction(string)

Groups every edit made until the returned object is disposed into one undo step.

public IDisposable BeginTransaction(string description)

Parameters

description string

What the step does, as UndoDescription reports it.

Returns

IDisposable

The transaction; dispose it to close it. Transactions nest; only the outermost one records a step.

Exceptions

ArgumentException

description is null or empty.

ObjectDisposedException

The document's session was disposed.

ClearAttribute(NodeId, string)

Removes an attribute, so the property falls back to its style or default value.

public EditResult ClearAttribute(NodeId node, string name)

Parameters

node NodeId

The element.

name string

The attribute name as written in markup.

Returns

EditResult

The outcome; a success that changed nothing when the element has no such attribute.

Remarks

Refused while IsInSync is false: fix the markup first.

Exceptions

ArgumentException

name is null or empty.

ObjectDisposedException

The document's session was disposed.

InsertElement(NodeId, int, string)

Inserts an element written in markup as a content child of parent.

public EditResult InsertElement(NodeId parent, int index, string markup)

Parameters

parent NodeId

The element to insert into.

index int

The position among parent's content children (property elements such as <Grid.RowDefinitions> don't count), from 0 to their count.

markup string

Exactly one element, such as <Button Padding="12,6">OK</Button>.

Returns

EditResult

The outcome; on success Node is the inserted element.

Remarks

Refused while IsInSync is false: fix the markup first.

Exceptions

ArgumentNullException

markup is null.

ObjectDisposedException

The document's session was disposed.

MoveElement(NodeId, NodeId, int)

Moves an element to another parent, or to another position in the same parent. The live element keeps its identity and runtime state.

public EditResult MoveElement(NodeId node, NodeId newParent, int index)

Parameters

node NodeId

The element to move. It can't be the root.

newParent NodeId

The element to move it into. It can't be node or inside it.

index int

The position among newParent's content children, counted without node.

Returns

EditResult

The outcome.

Remarks

Refused while IsInSync is false: fix the markup first.

Exceptions

ObjectDisposedException

The document's session was disposed.

RemoveElement(NodeId)

Removes an element and everything in it.

public EditResult RemoveElement(NodeId node)

Parameters

node NodeId

The element to remove. It can't be the root.

Returns

EditResult

The outcome.

Remarks

Refused while IsInSync is false: fix the markup first.

Exceptions

ObjectDisposedException

The document's session was disposed.

SetAttribute(NodeId, string, string)

Sets an attribute, adding it when the element doesn't have it yet.

public EditResult SetAttribute(NodeId node, string name, string value)

Parameters

node NodeId

The element.

name string

The attribute name as written in markup: Width, Grid.Row, x:Name.

value string

The value as the property should receive it, or a markup extension such as {Binding Path=Name}. It is escaped for the attribute's quote character; don't escape it yourself.

Returns

EditResult

The outcome.

Remarks

Refused while IsInSync is false: fix the markup first.

Exceptions

ArgumentException

name is null or empty.

ArgumentNullException

value is null.

ObjectDisposedException

The document's session was disposed.