Chapter 23 Notes
Title: Triggers and behaviors
Summary
Relates to XAML allowing triggers and behaviors.
Programming Concepts Summary
Concept |
Page |
Programs
Program EntryPop
Page 837.
Concepts:
- Shows an Entry changed by a trigger. .
Program EntryPopCode
Page 839.
- Shows previous program but set in code. Not interesting really since the whole purpose was to do it in XAML.
However there is no support for animations in XAML, this requires code! See new class: Easing on page 432.
Program EntrySwell
Page 844.
Shows the implementation in XAML of a ScaleAction.
New Classes:
EnterExitSwell
Page 846.
- Demo's both directions...
New Classes:
Trigger.EnterActions
Trigger.ExitActions
Program ButtonGrowth
Page 849
- Demo's making buttons grow and shrink.
Program SiverButtonDemo
Page 851.
- Like it says make it shiver ... its more about the toolkit!
Don't have a tapped event? Use a behavior p. 851... Later!
Program TriggerEntryValidation
Page 852.
Data Trigers
Program GenderColors
Page 854.
- Sets text blue or pink on the color base on gender. (See p. 855)
Program ButtonEnabler
Page 856.
- Sets the button enabled based on value of an Entry view.
Program AndConditions
Page 859.
- Hmm. Multi-Triggers default to an "AND" condition. Mildly interesting. Value=True...
Program OrConditions
Page 861.
- Ahh, you can set it to be an OR condition too. Even less Mildly interesting. Value=False...
Program XorConditions
Page 866.
- Yeeaasss! We can do XOR too.
Behaviors Anything you can do with a Trigger you can also do with a Behavior. However, a behavior always involves some code, which is a class that derives from Behavior<T>. Triggers only involve code if you’re writing an Action<T> derivative for an EventTrigger or for EnterActions or ExitActions collections of the other triggers.
Program TriggerEntryValidation
Finally this is important!
Page 868.
New Classes:
Program EmailValidationDemo
Page 872.
- Demo this one it has Regular Expressions in it!
Program EmailValidationTrigger
Page 876.
Demos the use of a trigger with EmailValidation
Toggles and Check boxes
Program ToggleLabel
Page 877.
- Demos the ability to use a button like a toggle.
Program FormattedTextTogle
Page 878.
Expands previous program: Of course, such a program would probably need to run some code when the Label is toggled. Keep in mind that Behavior derives from BindableObject, which means that any BindableProperty that you define in a behavior automatically generates a PropertyChanged event when the property changes.
This means that you can attach a handler to the PropertyChanged event of ToggleBehavior and check for changes in the IsToggled property. This is demonstrated in the FormattedTextToggle program.
Program TraditionalCheckBox
Page 881.
uses two Unicode characters for an unchecked box and a checked box, similar to the CheckBox views in Chapters 15 and 16.
Program SwitchCloneDemo
Page 884.
- It’s entirely done in XAML!
- Yuk, the XAML one didn't work, so they included a Code only version .... SKIP IT!
Program LeverToggle
Page 888.
Fun with BoxView elements... skippable.
Responding to Taps: The various manifestations of toggle views demonstrate one way to respond to taps within a XAML file. If tap events were integrated into the VisualElement class, you could get at them more directly and with greater ease using EventTrigger. But you can’t attach an EventTrigger to a TapGestureRec-ognizer. Getting around that little restriction is the purpose of a behavior devoted solely to a tap. This is called TapBehavior (889)
Program BoxViewTapShiver
Page 891.
Attaches TapBehavior objects to three Box-View elements, each of which also includes a DataTrigger that references the behavior and invokes a ShiverAction in its EnterActions collection.
Program ShiverViews
Page 892.
If you want to cut down on the markup in this case, you’ll once again need to define a new class. The ShiverViews program demonstrates this.
Radio Buttons Page 893