Binding Code and Data to MCML
Data binding is the way in which you bind code and data to MCML. ModelItem objects are code-supported objects that represent the most common abstract data and callback concepts and are strictly non-visual. These objects should be used as the main interface to the UI controls that are defined in your MCML markup.
The ModelItem class implements the IPropertyObject interface, and provides the following features:
Direct simple bindings, which allow you to associate a property on your ModelItem object with a property on another object, or vice versa. For the ModelItem object to detect property changes on a different object, the other object must implement the IPropertyObject interface.
For convenience, you can use the following ModelItem methods for binding to other code objects:
Lifetime management. ModelItem objects are typically connected to many other objects through event handlers and other methods. To prevent common leaks, each ModelItem must be owned by an IModelItemOwner object. That owner then takes responsibility for disposing the owned ModelItem objects.
The ModelItem class implements the IModelItemOwner interface; one ModelItem can own others, thereby ensuring that ModelItem objects that are being referenced by another ModelItem object are automatically disposed and released. For example, a page ModelItem object could own all of the ModelItem objects on the page.
Windows Media Center supports binding data from any .NET object, as well as generalized data sources through a set of data interfaces. If the source exposes IPropertyObject notifications, MCML rules can automatically respond.
Note Your code cannot access UI elements—UI elements own the data-binding relationship, rather than the code owning it.
- Deriving from the ModelItem class is easier and quicker. This class requires a constructor to be instantiated on the application thread. Objects derived from ModelItem cannot be remoted.
- Deriving from the IModelItem interface requires more work; you must implement the entire interface and implement your own change notifications. However, deriving from this interface gives you more control and better performance for your application.
The Microsoft.MediaCenter.UI namespace provides the ModelItem class and the following derived classes that you can use directly:
|Choice||Maintains a list and the item within it that is selected. This class is useful when you want to implement a radio button group.|
|BooleanChoice||Maintains a list of two options (True and False) and the item that is selected. This class is useful when you want to implement a check box.|
|Provides callback functionality so you can connect the UI to the program state. For example, use one of these classes with a UI button to receive click notifications.|
|EditableText||Represents an editable string. This class is useful when you want to implement an edit box.|
|ListDataSet||Maintains a list of objects for a list or a gallery in the UI. These classes raise events for add, remove, and modified notifications, which are compatible with Repeater view items.|
|RangedValue||Maintains a range of values. For example, use these classes to implement a spinner control or a slider control.|
|Timer||Creates a configurable timer that raises notifications on clock ticks (that is, specific intervals).|
|PropertySet||Provides a loosely-typed dictionary that raises notifications. However, when possible, use a strongly-typed structure instead. This class works well where data structures are required, but custom code is not possible (such as web applications).|
- Model Items > Secure Editable Text
- Code and Data > Model Item
- Code and Data > Threading
- Code and Data > Virtualization