Wiki Navigation
- Loading...
Themes, MPF resources and bindings
In MPF, we have objects in two different functions:
- Rendered elements in the visual tree of a screen (Panel, Control, ...)
- Elements which are used as resources (Style, ResourceDictionary, ControlTemplate, DataTemplate, ResourceWrapper, ...)
We want bindings to be active on objects of the first category (rendered objects) but not on elements of the second category (resources).
To achieve that, we use this strategy to activate bindings:
- We mark resources with interface IBindingContainer.
- When created, bindings are not yet activated.
- When the binding is attached to its context object (and added to it's binding collection), it is automatically remembered to maybe activated later. That is done by searching the next LogicalParent which implements IBindingContainer or, if no such LogicalParent is found, to the topmost parent.
- If its LogicalParent is assigned later, the bindings are propagated further and the local pending bindings collection is cleared.
- If an IBindingContainer is found, the new binding is handled by that container. UI elements, for example, will activate bindings when their ElementState becomes Preparing or Running. Until that state, pending bindings are just stored. Other binding containers simply drop pending bindings because they will never bind. That's done in ControlTemplates and Styles, for example.
To make it work, the LogicalParent property is assigned for each object which is not an UI element and whose bindings should be able to be activated.
This page has no comments.