Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

View model

In addition to the model that maintains the widget's data, the widget also has a view model that is used to observe events that have an impact on the visible state of a widget and send notifications of those events to all registered observers. Those observers can be internal to the widget as well as external (for example, another widget or an application might be interested in view model events). To receive model notifications, an application can attach a listener to a model.

Notifications can contain information such as the following:

  • Extent changes
  • Invalidations
  • New data models being set to the widget
  • Widget element selection (such as in lists)

The view model can be retrieved by calling IWidget_GetViewModel().

A good example of the use of view models in widgets is the symbiotic relationship of the tab widget and the card container. The tab widget view notifies the card container when the user changes the currently selected tab and correspondingly, the card container notifies the tab widget when the currently active card (widget) is changed by an entity besides the tab widget.

For more information on attaching a model listener to a view model, see Creating a model listener for a button.