= Chapter 7 Notes =
Title: '''XAML vs. Code'''
== Summary ==
* XAML is a better way to write up the "view" part of MVVM.
* XAML is used to write the tree-structured visual user interface
== 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!
{{{#!csharp
[TypeConverter (typeof(ColorTypeConverter))]
public struct Color
{
…
}
}}}
'''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.
* {{{ ... }}} is a ''object element''
* {{{ ... }}} is a ''property element''
* In {{{ ... }}}, {{{VerticalOptions}}} is a property attribute.
'''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.
{{{#!csharp
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
}}}
== Programs ==
=== CodePlusXaml ===
Page 140
Concepts:
1. Shows how to create a XAML page in an existing document
1. Shows code behind
1. Shows XML namespaces required.
1. xmlns="http://xamarin.com/schemas/2014/forms"
1. 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.
1. Shows how to define the class that the objects defined in this fill will belong to:
1. x:Class="CodePlusXaml.CodePlusXamlPage"
1. 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.
1. .xaml.g.cs where the g is for generated.
1. See obj/Debug folder for generated files for XAML
1. 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
1. Shows how to nest object elements, property attributes and property elements properly.
1. Shows code behind concepts
1. 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(...)}}})
1. ... otherwise no new classes demonstrated.
=== TextVariations ===
Page 152
1. Shows various ways of formatting text in XAML.
1. 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).