Control tilt effect for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

The tilt effect for Windows Phone controls provides you with the ability to add additional visual feedback for control interaction. Instead of having standard pressed or un-pressed states, controls with the tilt effect provide motion during manipulation. The result is a “tilt”-like response when the control is touched. This topic discusses the tilt effect architecture and implementation.

This topic contains the following sections.

Tilt effect architecture

The tilt effect is a custom dependency property (IsTiltEnabled) that you can add to controls such as a Button. This dependency property is defined in a custom class file called TiltEffect.cs. The file also provides the code necessary to create the visual tilt effect on the controls. When an item is tapped, this TiltEffect class will search for specified controls that have the property enabled and apply the effect. You can apply the dependency property globally so that all controls in the visual tree inherit the tilt effect, or you can apply the dependency property to only a single control if desired.

The TiltEffect.cs file also defines a second dependency property (SuppressTilt) that can suppress the tilt effect on a control. A scenario for which you might want to use this property is when you want to apply the tilt effect globally on a page, but want to exclude a specific control on the page from using the tilt effect.

Name

Type

Description

IsTiltEnabled

Dependency Property

Bool: This dependency property allows you to apply the tilt effect in your application. You can apply it globally or to single controls.

SuppressTilt

Dependency Property

Bool: This dependency property allows you to suppress the tilt effect on a control.

Tip

The TiltEffect.cs file is incorporated into a downloadable sample at Control Tilt Effect Sample. You must download the sample and import the code into your project to implement the tilt effect to your controls. The How to use the control tilt effect for Windows Phone 8 topic provides instructions for creating your tilt effect application.

Implementation overview

The high-level steps for implementing the tilt effect are the following:

  1. Importing the code from the TiltEffect.cs file into your project

  2. Applying the IsTiltEnabled dependency property either globally or to selected controls in your project

  3. Optionally, applying the SuppressTilt dependency property to selected controls in your project

The following TiltEffect.cs file code segment creates a tiltable items list:

public static List<Type> TiltableItems { get; private set; }

        static TiltEffect()
        {
            TiltableItems = new List<Type>() { typeof(ButtonBase), typeof(ListBoxItem),};
        }

When a control is tapped, the TiltEffect class will search for specified controls that have the tilt effect enabled. By default, the general ButtonBase class and ListBoxItem controls are specified as tiltable items. If a control type were not present here, the tilt effect would not be applied to any controls even if the IsTiltEnabled dependency property is attached and set to True. You should not modify this code segment directly to add support for additional controls. Instead, you should update the list from your own code, such as using a segment like the following:

TiltEffect.TiltableItems.Add(typeof(“MyCustomControl”))

However, adding additional built-in controls is not recommended because the tilt behavior will be inconsistent in the application.

See Also

Other Resources

How to use the control tilt effect for Windows Phone 8