Chapter 8 Notes

Title: Code and XAML in harmony

Summary

This chapter shows how to create interactions between code and the elements in a XAML file.

Programming Concepts Summary

Programs

ParameteredConstructorDemo

Page 159.

Concepts:

  1. Shows how to include parameters in XAML.
  2. The number and type of parameters must match an existing constructor.

Classes:

No new classes

FactoryMethodDemo

Page 159.

Concepts:

  1. Shows how to create an object using a FactoryMethod.

Classes:

No new classes

XamlClock

Page 161.

Concepts:

  1. Shows a better approach to accessing XAML object/elements by giving them a name.
  2. x:Name="..." is introduced and the text name must meet C# naming rules.
  3. You can find the "magic" in the generated file: XamlClockPage.xaml.g.cs

    1. Every x:Name attribute becomes a private field in this generated code.
    2. Objects named with x:Name will only be available after the call to InitializeComponent.

  4. Includes the concept of a Timer and an OnTimerTick() handler.

Classes:

No new classes

PlatformSpecificLabels

Page 164.

Concepts:

  1. Shows how to create a platform specific Label - but the first go, won't allow you to x:Name them.
  2. Also all the Labels will be created, but only one of them will be assigned to the ContentPage default value - Content.

  3. Also, ContentPage.Content is a View, and consequently the x:TypeArguments="View" - of course this is ok because Label inherits from view.

  4. The solution is to push the OnPlatform into the Label as shown int the final version.

Classes:

No new classes