concept bindingContext in category nativescript

appears as: bindingContext
NativeScript in Action

This is an excerpt from Manning's book NativeScript in Action.

In listing 8.13, we are using a button tap event to access the binding context the scrapbook page. When a tap event is handled, the handler passes a reference to the page via the object property, so args.object is a reference to the page. With a reference to the page, the bindingContext property has a reference to the original observable, which contains all the data bound properties.

The page’s binding context is inherited to all child elements, and stored in a property called bindingContext on each element.

You may have come up with a different solution, but the way we’ll solve this problem will help you better understand the process of data binding and the inheritance of the binding context. In the tip, you learned that each UI element has a property named bindingContext, which is inherited from its parent element.

Even though we’ve set the bindingContext property on the page only, there’s not a reason why we can’t set the binding context on another control, breaking the inheritance chain. Let’s do just that by getting a reference to the stack layout surrounding the update UI elements in code and setting its binding context to the selectedPage observable. Listings 11.18 and 11.19 show the changes to XML and JavaScript code used to get a reference to the surrounding stack layout mentioned above.