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
- Elements in a XAML file are instantiated with a parameter-less constructor.
- To over come this we (seldom) use:
x:Arguments
x:FactoryMethod
- Custom XAML-based views
Programs
ParameteredConstructorDemo
Page 159.
Concepts:
- Shows how to include parameters in XAML.
- The number and type of parameters must match an existing constructor.
Classes:
No new classes
FactoryMethodDemo
Page 159.
Concepts:
Shows how to create an object using a FactoryMethod.
Classes:
No new classes
XamlClock
Page 161.
Concepts:
- Shows a better approach to accessing XAML object/elements by giving them a name.
- x:Name="..." is introduced and the text name must meet C# naming rules.
You can find the "magic" in the generated file: XamlClockPage.xaml.g.cs
- Every x:Name attribute becomes a private field in this generated code.
Objects named with x:Name will only be available after the call to InitializeComponent.
Includes the concept of a Timer and an OnTimerTick() handler.
Classes:
No new classes
PlatformSpecificLabels
Page 164.
Concepts:
- Shows how to create a platform specific Label - but the first go, won't allow you to x:Name them.
Also all the Labels will be created, but only one of them will be assigned to the ContentPage default value - Content.
Also, ContentPage.Content is a View, and consequently the x:TypeArguments="View" - of course this is ok because Label inherits from view.
The solution is to push the OnPlatform into the Label as shown int the final version.
Classes:
No new classes
ColorViewList
Page 168.
Concepts:
CustomViewList shows how to create a custom view that can be used over and over again.
Shows how the CustomViewList has a string property color that uses a Converter
Shows how to use the CustomerViewList in the main XAML page
Classes:
No new classes
XamlKeypad
Page 172.
Concepts:
- Assign handlers in XAML
Classes:
No new classes
MonkeyTap
Page 176.
Concepts:
- An actual game that brings together all the things we have learned.
Classes:
No new classes