Extending XAML Applications With Behaviors

Behaviors let you add functionality to existing controls and elements in a declarative fashion in your XAML. This course shows you how to use the built-in Blend behaviors to cover a wide range of scenarios and how to implement your own custom behaviors for any scenario as well.
Course info
Rating
(151)
Level
Intermediate
Updated
May 23, 2014
Duration
2h 48m
Table of contents
Behaviors Overview
Blend Behaviors, Triggers, and Actions
Invoking Logic With Behaviors
Managing Visual State With Behaviors
Animating Elements With Behaviors
Custom Behaviors
Description
Course info
Rating
(151)
Level
Intermediate
Updated
May 23, 2014
Duration
2h 48m
Description

When building XAML applications in WPF, Silverlight, Windows 8, or Windows Phone, you will often find yourself saying, "If only this element had the ability to do X, Y, or Z from the XAML!" Behaviors are a pattern of extensibility in XAML that allow you to add capabilities to existing XAML elements yourself, even if you don’t have access to the source code of the elements you are trying to extend. You can extend elements that are part of the core XAML libraries, 3rd party controls, or even your own controls all using a set of pre-built behaviors or by building your own custom behaviors. In this course, you will learn what behaviors are all about, how they are built and work, and why you want to use them. You'll learn how to get highly productive quickly by using the pre-built Blend SDK and Behaviors SDK built-in behaviors, as well as how to build custom behaviors from scratch for more specialized scenarios. You will see how the same set of skills and built-in behaviors will allow you to apply the same kinds of functionality across the different XAML stacks of WPF, Windows 8, Windows Phone, and Silverlight.

About the author
About the author

Brian Noyes is CTO and Architect at Solliance, an expert technology solutions development company. Brian is a Microsoft Regional Director and MVP, and specializes in rich client technologies including XAML and HTML 5, as well as building the services that back them with WCF and ASP.NET Web API.

More from the author
Securing Angular Apps with OpenID and OAuth2
Intermediate
2h 30m
27 Jul 2018
WPF Productivity Playbook
Intermediate
2h 57m
22 Aug 2016
More courses by Brian Noyes
Section Introduction Transcripts
Section Introduction Transcripts

Blend Behaviors, Triggers, and Actions
Hi. This is Brian Noyes. In this module we'll be covering the Blend experience of working with behaviors, we'll learn about the differences between behaviors, triggers, and actions, and we'll see how to use those in the Blend Design-Time environment. First off we're going to start with the definitions of behaviors, triggers, and actions, and you'll see that these are all collectively treated as behaviors, but behavior is a type, trigger and action are types that are different kinds of behaviors in general. Next we'll look at what the Design-Time experience is for working with Blend behaviors in WPF and Silverlight, followed up with the Design-Time experience of working with them in WinRT, and we'll see that in the form of demos, so let's dive right in.

Invoking Logic With Behaviors
Hi. This is Brian Noyes. In this module we're going to cover a number of behaviors that allow you to invoke logic in your application, including the InvokeCommandAction, CallMethodAction, and ChangePropertyAction behaviors. First up we'll talk about some generalities about the logic oriented behaviors and how to use them, then we'll dive into the InvokeCommandAction, which lets you execute a Command object when some trigger fires. Next we'll talk about the CallMethodAction, which lets you invoke a method when its trigger fires, and then we'll finish off with the ChangePropertyAction, which lets you set a property when its trigger fires. Let's just dive right in and see all these in action, so to speak.

Managing Visual State With Behaviors
In this module we're going to take a look at a couple of behaviors that let you manage Visual States and the transitions between them. First up we'll do a quick review of what the Visual State Manager is. It's a platform level feature in XAML platforms that let you manage the Visual State or transitions between different Visual States of your UI. Then we'll look at the GoToStateAction, which is the first behavior that allows you to command a transition between states based on a trigger. The second behavior we'll look at in this module is called the DataStateBehavior and it is particular to the Blend SDK, so not available on WinRT platforms, and it's very similar to the GoToStateAction. In fact, anything you can do with the DataStateBehavior you could do with one or more GoToStateActions, but it does make the state transitions a little more convenient for scenarios where you're going to toggle between two states based on a single property, so let's dive into Visual States, what they are, and how to use these behaviors to cause transitions between them.

Animating Elements With Behaviors
In this module we're going to look at a collection of behaviors that'll let you do various forms of animation or manipulation of those elements within the user interface. Now every one of the behaviors I'm going to be covering in this module is only available in the Blend SDK, so if you're building for a Windows 8 or a Windows Phone 8. 1 and using the Behaviors SDK, this module does not apply. First we're going to look at something called the FluidMoveBehavior. This gives you a very easy ability to have some natural, visual transitions when elements are moving around on the screen. Next up we'll look at a MouseDragElementBehavior that enables an element that has no knowledge of being able to be dragged to very easily do so. Next up we'll look at RemoveElementAction, which is very simple to use and in nature, basically it allows you to have some trigger cause an element to be removed from its parent container. Next we'll look at the longest named behavior, FluidMoveSetTagBehavior, and this one works in conjunction with the FluidMoveBehavior to enable _____ type scenarios where you have two related elements on the screen and you want to visual transition to fly from one element to another, such as in master detail type scenarios. Finally, we'll finish off with the TranslateZoomRotateBehavior that enables touch gestures on a touch-based system, so the user can manipulate the element and see it being manipulated in an animated way. Let's just dive right in and talk about all these.

Custom Behaviors
Hi. This is Brian Noyes. In this final module I'm going to show you how to unlock the full potential of behaviors and that is by writing your own custom behaviors. The approach to writing custom behaviors is slightly different between the Blend and Behaviors SDK, we'll cover that. We'll also cover a number of example scenarios, so you can get a sense of the kinds of things you can do in your own custom behaviors, and you'll see the syntax of how you declare them and get them hooked up. First up we're going to talk about some concepts behind implementing custom behaviors. We'll talk about what you need to know to implement custom behaviors and go through a number of sample scenarios that I've worked on in the past where I ended up implementing custom behaviors. Next we'll get into some samples and I'll show you how to implement a Custom Blend SDK Behavior from scratch and some of the considerations that go into that implementation. Then we'll look at a Custom Trigger scenario for the Blend SDK as well and we'll finish off by walking through a number of sample Behaviors SDK behaviors using some code that actually comes from the Prism for Windows Runtime library.