Chapter 11 Notes

Title: The Bindable Infrastructure

Summary

This will be our introduction to binding views to properties, i.e. Data Binding.

Programming Concepts Summary

Concept

Page

Property

227

Xamarin enhances property definition and encapsulates this enhanced property in the BindableProperty class.

227

BindableProperty objects are used to store the data associated with a BindableObject

22 + Docs online

In general there are two extremely important concepts in CS: abstraction and layering.

Properties are an abstraction of implementing getters and setters for a field. The abstraction allows the the user to treat the property like a field (variable), and as such we are abstracting away the details of getters and setters so that the user of a property does not have to remember to use a getter and setter when dealing with a property vs. a normal field variable.

The class hierarchy project shows the process of layering functionality. Functionality shared by every object is at the top of the inheritance tree, and every object inherits from that object directly or through an inheritance chain. This is demonstrated nicely in the ClassHierarchy program.

Programs

Program ClassHierarchy

Page 228.

Concepts:

  1. Shows how to walk the Xamarin.Forms class hierarchy so that we can see how the classes are related.
  2. General functionality is defined and implemented higher in the hierarchy this includes all functionality (and implementation code) shared by the children. Although this may seem obvious to say, I want to emphasize that this is a layering technique similar to what you learned in CPTR 328 (Principles of Networking). I.e. different functionality is defined at different layers in the inheritance hierarchy.

Classes:

  1. ClassesAndSubclasses is a data class used to build the hierarchy.

  2. TypeInformation adds some functionality needed to interrogate types.

  3. ClassHierarchyPage : ContentPage contains most of the functionality.

Program PropertySettings

Page 235.

Concepts:

  1. Exposes the underlying BindableObject by calling the label1.SetValue(Label.TextProperty, "Some Text"); function instead of using the common shortcut method of label1.Text="Some Text");

    1. Label.TextProperty is a BindableObject defined in the Label class as:

   1 public static readonly BindableProperty TextProperty;