Chapter 7 Notes

Title: XAML vs. Code

Summary

Concepts Not in programs

Converter Classes

Page 134

Below the Color class has a TypeConverter attribute added. Attributes in this context means that the defined attributed class is added to the decorated class. That means that you may have additional properties because of the decoration. You might say that Color now has a TypeConverter object that is instantiated with a Type - in this case the: typeof(ColorTypeConverter)

This, of course, means that Color has additional functionality! We'll learn more about this later!

   1 [TypeConverter (typeof(ColorTypeConverter))]
   2 public struct Color
   3 {
   4 
   5 }

Property-[Element|Attribute] Syntax:

Page 136

This section spells out how to translate some of the code we are used to writing into XAML. Specifically it identifies how XML elements and attributes map to objects and contents.

XAML Compiler

Page 145

You can force your output to compile the XAML instead of using it directly. This saves time and space, but is new and therefore suspect. Add the following line to your Assembly.cs file in the properties folder.

   1 [assembly: XamlCompilation(XamlCompilationOptions.Compile)]

Programs

CodePlusXaml

Page 140

Concepts:

  1. Shows how to create a XAML page in an existing document
  2. Shows code behind
  3. Shows XML namespaces required.
    1. xmlns="http://xamarin.com/schemas/2014/forms"

    2. xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" NOTE: the x: is by convention, so you should use it that way, but it is not strictly required that the name be x.

  4. Shows how to define the class that the objects defined in this fill will belong to:
    1. x:Class="CodePlusXaml.CodePlusXamlPage"

  5. Shows where generated code can be found and how to expose it.
    1. In Visual Studio, in the Solution Explorer, select the CodePlusXaml project, find the icon at the top with the tooltip Show All Files, and toggle that on.

    2. .xaml.g.cs where the g is for generated.
    3. See obj/Debug folder for generated files for XAML
  6. A simple way to identify the Content - its available, just make sure to cast it correctly.

ScaryColorList

Page 146.

Concepts:

  1. Shows how to do OnPlatform in XAML

  2. Shows how to nest object elements, property attributes and property elements properly.
  3. Shows code behind concepts
  4. introduces the concept of a default property (p. 151) and the ConntentPrpoertyAttribute.

Classes:

  1. OnPlatform class was used (as a variation of the Device.OnPlatform(...))

  2. ... otherwise no new classes demonstrated.

TextVariations

Page 152

  1. Shows various ways of formatting text in XAML.
  2. if you prefer to use multiple lines, you should left justify the whole paragraph in the XAML file surrounded by quotation marks. (See page 154).

ManagingAndProgrammingMobileApplications/Xamarin/Chapter 7 (last edited 2016-09-13 00:13:55 by scot)