Using Object Paths

Object paths are the main form of data binding in MCML. Using object paths, you can dot into any common language runtime (CLR) object using the form [ObjectName.Member. ... .Member].

ObjectName is the first part of the path, and refers to a named object within the scope of the UI, with the following restrictions:

  • You cannot use object paths in a Properties section.
  • In a Locals section, object paths have access to objects in the Properties section.
  • In a Content section, object paths have access to objects in the Properties and Locals section.
  • In a Rules section, object paths have access to objects in the Properties, Locals, and Content sections.

Object paths can be used to access property, method, and indexer members.

The following example shows how to call a static property from the System.DateTime structure. First, declare the type in the Locals section (DateTime also requires a reference to the System namespace). Then, using object paths, you can access the DateTime properties in the Content section of the UI:

<Mcml
  xmlns="https://schemas.microsoft.com/2008/mcml"
  xmlns:cor="assembly://MSCorLib/System" >
  <UI Name="Statics">
    <Locals>
      <cor:DateTime Name="Display" />
    </Locals>
    <Content>
      <Text Content="[Display.Now.ToString]" Color="White" />
    </Content>
  </UI>
</Mcml>

Indexers can be used to access dictionaries with the following syntax (where "#" indicates an indexer):

MyDictionary.#IndexerValue

Object paths support type-casting and type conversions to declare that the current member type is a different type. Use "!" to indicate a type cast as follows:

Data.Item!cor:String

The Item property is of type Object, and cor is a namespace prefix (for example, xmlns:cor="assembly://MSCorlib/System").

You can use type-casting in the following situations:

  • Casting to or from an interface
  • Casting to a valid derived type (up-cast)
  • Casting to a valid base type (down-cast).

Type conversions are used to convert an object to a different type. A type conversion uses the same casting syntax and is considered when type-casting is not allowed. For example, [MyString!Image] converts a string to an Image type using the built-in type converter for the Image object. Type casts and type conversions are validated at run time, and can result in fatal run-time errors.

Note   Type conversions are only allowed for primitive and string types.

Most object paths are evaluated when the UI is created and the resulting values are set on the associated properties. However, for the following elements, the object paths are re-evaluated at run-time as needed:

You may not name any of the objects in your UI with any of the following reserved names:

  • Input
  • RepeatedItem
  • RepeatedItemIndex
  • Accessible

Sample Explorer

  • Fundamentals > Object Paths

See Also