Table of Contents

Class MarkupLoader

Namespace
Icy.Markup
Assembly
IcyUI.dll

Builds a UIElement tree from a markup document.

public class MarkupLoader : IMarkupBuilder
Inheritance
MarkupLoader
Implements
Inherited Members
Extension Methods

Remarks

The loader walks the XML once, and for each element resolves its type, constructs an instance through Activator, applies its attributes, then applies its children - in that order, so that a container's own properties are set before anything is added to it.

Every object it creates is constructed inside a UseScope(PropertyRegistry) for the configuration's own registry, so the tree and the loader that resolves its properties always agree on which registry they are using - see the remarks on PropertyRegistry for why mixing two would compute wrong values.

Loading is all-or-nothing: the first error raises a MarkupException carrying the file position, and no partially-built tree is returned.

The loader also implements IMarkupBuilder, the seam design tooling uses to build fragments and apply single attributes in the context of an already loaded document.

Constructors

MarkupLoader(IcyConfiguration)

Builds a UIElement tree from a markup document.

public MarkupLoader(IcyConfiguration configuration)

Parameters

configuration IcyConfiguration

The configuration supplying type resolution, conversion, and the property registry.

Remarks

The loader walks the XML once, and for each element resolves its type, constructs an instance through Activator, applies its attributes, then applies its children - in that order, so that a container's own properties are set before anything is added to it.

Every object it creates is constructed inside a UseScope(PropertyRegistry) for the configuration's own registry, so the tree and the loader that resolves its properties always agree on which registry they are using - see the remarks on PropertyRegistry for why mixing two would compute wrong values.

Loading is all-or-nothing: the first error raises a MarkupException carrying the file position, and no partially-built tree is returned.

The loader also implements IMarkupBuilder, the seam design tooling uses to build fragments and apply single attributes in the context of an already loaded document.

Methods

Load(Stream, string?)

Loads a markup document from a stream.

public UIElement Load(Stream stream, string? sourcePath = null)

Parameters

stream Stream

The stream to read the document from.

sourcePath string

The document's path, used only to make error messages locatable.

Returns

UIElement

The root element the document declares.

Exceptions

MarkupException

The document is malformed, or breaks a rule of the language.

Load(TextReader, string?)

Loads a markup document from an already-parsed TextReader.

public UIElement Load(TextReader reader, string? sourcePath = null)

Parameters

reader TextReader

The reader positioned at the start of the document.

sourcePath string

The document's path, used only to make error messages locatable.

Returns

UIElement

The root element the document declares.

Exceptions

MarkupException

The document is malformed, or breaks a rule of the language.

Load(string, string?)

Loads a markup document from a string.

public UIElement Load(string text, string? sourcePath = null)

Parameters

text string

The markup document.

sourcePath string

The document's path, used only to make error messages locatable.

Returns

UIElement

The root element the document declares.

Exceptions

MarkupException

The document is malformed, or breaks a rule of the language.

LoadDataTemplateContent(XElement, string?)

Builds a fresh visual tree from a DataTemplate's already-parsed content.

public UIElement LoadDataTemplateContent(XElement content, string? sourcePath = null)

Parameters

content XElement

The template's root element, captured once when the DataTemplate itself was loaded (see CreateObject(XElement, MarkupLoadContext)'s DataTemplate special case) - not re-parsed from text here.

sourcePath string

The template's source document path, used only to make error messages locatable.

Returns

UIElement

The freshly built root element.

Remarks

The DataTemplate equivalent of LoadTemplateContent(XElement, UIElement, string?), minus the templatedControl a DataTemplate has no use for - it supports no {TemplateBinding}, so nothing in the built content ever needs to reach back to a "templated control".

Exceptions

MarkupException

content is malformed, breaks a rule of the language, or its root doesn't build a UIElement.

LoadObject(Stream, string?)

Loads a markup document from a stream whose root need not be a UIElement.

public object LoadObject(Stream stream, string? sourcePath = null)

Parameters

stream Stream

The stream to read the document from.

sourcePath string

The document's path, used only to make error messages locatable.

Returns

object

The root object the document declares.

Exceptions

MarkupException

The document is malformed, or breaks a rule of the language.

LoadObject(TextReader, string?)

Loads a markup document from an already-parsed TextReader whose root need not be a UIElement.

public object LoadObject(TextReader reader, string? sourcePath = null)

Parameters

reader TextReader

The reader positioned at the start of the document.

sourcePath string

The document's path, used only to make error messages locatable.

Returns

object

The root object the document declares.

Exceptions

MarkupException

The document is malformed, or breaks a rule of the language.

LoadObject(string, string?)

Loads a markup document whose root need not be a UIElement - a Style document, for instance.

public object LoadObject(string text, string? sourcePath = null)

Parameters

text string

The markup document.

sourcePath string

The document's path, used only to make error messages locatable.

Returns

object

The root object the document declares.

Exceptions

MarkupException

The document is malformed, or breaks a rule of the language.

LoadTemplateContent(XElement, UIElement, string?)

Builds a fresh visual tree from a ControlTemplate's already-parsed content, for one specific control applying that template.

public UIElement LoadTemplateContent(XElement content, UIElement templatedControl, string? sourcePath = null)

Parameters

content XElement

The template's root element, captured once when the ControlTemplate itself was loaded (see CreateObject(XElement, MarkupLoadContext)'s ControlTemplate special case) - not re-parsed from text here.

templatedControl UIElement

The control this content is being built for. Threaded into every MarkupExtensionContext this call resolves, so a {TemplateBinding} inside content can reach it.

sourcePath string

The template's source document path, used only to make error messages locatable.

Returns

UIElement

The freshly built root element.

Remarks

Called once per control instance that applies a given ControlTemplate - never caches or shares the built tree, since two controls using the same template must each get their own independent visual subtree (matching how every other Load/LoadObject overload never shares state across calls either).

Exceptions

MarkupException

content is malformed, breaks a rule of the language, or its root doesn't build a UIElement.

Load<T>(string, string?)

Loads a markup document and requires its root to be a T.

public T Load<T>(string text, string? sourcePath = null) where T : UIElement

Parameters

text string

The markup document.

sourcePath string

The document's path, used only to make error messages locatable.

Returns

T

The root element the document declares.

Type Parameters

T

The type the document's root element is expected to have.

Exceptions

MarkupException

The document is malformed, breaks a rule of the language, or its root is not a T.

ParseDocument(TextReader, string?)

Parses the document text into an XDocument with position information.

protected static XDocument ParseDocument(TextReader reader, string? sourcePath)

Parameters

reader TextReader

The reader positioned at the start of the document.

sourcePath string

The document's path, used only to make error messages locatable.

Returns

XDocument

The parsed document.

Remarks

The x prefix is predeclared on the reader, which is what lets a document use x:Name without an xmlns:x line of its own. A document that declares the prefix itself is unaffected - its own declaration simply shadows this one with the same value.

Exceptions

MarkupException

The document is not well-formed XML.