Docs / UI

Glossary: MarkupContext

The members of MarkupContext, in alphabetical order.

Color legend plain property method

What a markup reaches besides the UI’s own types: the object whose methods handle the events it names, the object its bindings read, the style dictionaries its keys name, where it finds and how it reads the files it includes, element and style types of your own, and converters for the property types it can’t read from text by itself. It also tells whether the animations a markup starts on load start as it is loaded.

A sealed class of the BorrowedTorch.UI.Markup package (namespace BorrowedTorch.UI.Markup). The markup page shows it in context.

Names are colored by what they are: a property, a method or an event; values and fields keep the plain color.

Properties

BaseDirectory 🠆

string · The directory a markup given as text finds the files it includes from (<Include Source="..." />). A markup loaded from a file finds them from the file’s own directory, an included one from its own. Without one, from the current directory. See including other files.

DataContext 🠆

object · The object {Binding Name} binds to, usually a Bindable view model whose changes the elements follow. A markup with a binding and no data context throws a MarkupException. See bindings.

Handlers 🠆

object · The object whose methods the events name: OnClick="StartGame" subscribes its StartGame method, public or not, taking the event’s parameters or none. See events.

MissingHandler 🠆

Action<object, string, string> · Called in place of a handler the markup names and Handlers doesn’t have (or with no handlers at all), whenever its event is raised: with the object raising it (the element), the event’s name and the handler’s name. Set, a missing handler is no error, so a tool can show a markup’s events without the game’s code; a handler that is there but takes other parameters still is one. See events.

ReadFile 🠆

Func<string, string> · Reads a markup file, given its full path: the one loaded from its file (LoadFile, LoadDocumentFile, LoadStylesFile) and the ones included. File.ReadAllText without one; a game whose files are elsewhere, such as in a content package, gives its own, and a tool may follow what is read with it.

StartsLoadAnimations 🠆

bool · Whether the animations a markup starts as it is loaded (StartOn="Load") are started then: true by default. false, they wait for MarkupDocument.StartLoadAnimations, and the elements keep their values as written: for a tool showing the UI as it is written until it is played. The animations started by events start on them either way. See animations in a tool.

Methods

MarkupContext() 🠆

MarkupContext() · Creates a context without handlers, data context, styles, types or converters.

AddConverter() 🠆

AddConverter<T>(Func<string, T> convert) · Reads the values of type T (and T?) from text, in place of the markup’s own way for that type. The markup reads text, numbers, enums, Color, Margin, Point, Vector2 and the types that convert from a string by itself. An exception the converter throws becomes the inner exception of a MarkupException. The converter reads the From and To of an animation too, so a property of type T can be animated, and UiMarkup.ReadValue given this context uses it. Returns this context, so the calls chain. A null converter throws an ArgumentNullException.

Parameter Type Description
convert Func<string, T> Turns the text of an attribute (or of a property element) into a value.

AddStyles() 🠆

AddStyles(StyleDictionary styles) · Makes the keyed styles of a style dictionary usable by their keys: Style="danger" gives an element the style as its StyleOverride, TextStyle="{Style title}" gives it to a style property. A key in more than one dictionary names the style of the one added last, and a UI’s own <Ui.Styles> comes before them all. The dictionary’s general styles are applied apart, with ApplyGeneralStyles. Returns this context, so the calls chain. A null dictionary throws an ArgumentNullException.

Parameter Type Description
styles StyleDictionary A dictionary read by LoadStyles or LoadStylesFile.

AddType() 🠆

AddType<T>() · Makes a type of your own usable by its name: an element (it needs a constructor taking its name), or a style or any other object a property element gives (it needs a constructor without parameters). It takes the place of a type of the UI with the same name. Returns this context, so the calls chain.