MOBILE

Windows Phone 7 : Working with Controls and Themes - Adding Transition Effects

2/12/2011 4:01:04 PM
To spice up your application, you can add what is called a "tilt" effect to the visual elements. The tilt effect provides visual feedback to the user of the Windows Phone 7 application during manipulation of visual elements within the application. So, instead of just "pressed" and "unpressed" states, elements can also have "being pressed" and "being unpressed" states. The integration of tilt is pretty straightforward, and in the end it will certainly be completely up to you whether you would like to use it within your application. But if you do decide to give this effect a try, follow this walkthrough.

1. Creating a User Interface

The user interface for the test application will be composed of four controls within the page: ListBox, Button, Hyperlink, and a Checkbox.

  1. Launch Visual Studio 2010 Express and select the Windows Phone Application template. Change the Project Name to "TiltableTest," select OK, and Visual Studio will set up a new project.

  2. Open MainPage.xaml in design mode, and add a ListBox with four items, a Button, a Hyperlink, and a Checkbox to the page, with the end goal of creating a user interface like the one shown in Figure 1.

    Figure 1. TiltableTest UI layout
  3. You can also paste the following XAML code to get the same interface depicted in Figure 9-7:

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

    <ListBox Height="110" HorizontalAlignment="Left" Margin="6,47,0,0" Name="listBox1"
    VerticalAlignment="Top" Width="460" ItemsSource="{Binding}" >
    <ListBoxItem Content="ListBoxItem 1" ></ListBoxItem>
    <ListBoxItem Content="ListBoxItem 2" ></ListBoxItem>
    <ListBoxItem Content="ListBoxItem 3" ></ListBoxItem>
    <ListBoxItem Content="ListBoxItem 4" ></ListBoxItem>
    </ListBox>
    <HyperlinkButton Content="HyperlinkButton" Height="30" HorizontalAlignment="Left"
    Margin="-109,185,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="409" />

    <Button Width="186" Height="85" Content="Button" HorizontalAlignment="Left"
    VerticalAlignment="Top" Margin="9,234,0,0" />


    <CheckBox Content="CheckBox" Height="72" HorizontalAlignment="Left"
    Margin="12,325,0,0" Name="checkBox1" VerticalAlignment="Top" />

    </Grid>

Now that you've added controls to the MainPage, in the next section, you will be adding Tilt effects to the controls you added.

2. Downloading TiltEffect.cs and Applying Dependency Properties

To integrate the Tilt effect into your application, you will need to download TiltEffect.cs and properly integrate it into your project.

  1. Download the Tilt Effect Control Sample from http://go.microsoft.com/fwlink/?LinkId=200720, and extract the contents of the zip file to a known location.

  2. From within the TiltableTest project you created previously, right-click the Add => Existing Item, navigate to the location from Step 1, and find the TiltEffect.cs file.

  3. With TitlEffect.cs now a part of your project, double-click that file to open it. Change the following statement as shown here.

    namespace ControlTiltEffect

    to

    namespace TiltableTest

Essentially, you just changed the namespace of this file so that it now belongs to your application.

  1. Now you need to add the IsTiltEnabled dependency property to the MainPage.xaml page. Open MainPage.xaml in a XAML view and, at the very top of the page, right below the xmlnss:mc=... add the following statement:

    xmlns:local="clr-namespace:TiltableTest"

  2. You are almost done—at the top of the page, beneath the statement

    shell:System Tray.IsVisible="True"

    add

    local:TiltEffect.IsTiltEnabled="True">

  3. Right-click the project and select Build. After the project builds, you are ready to run the application.

Press F5 to run the application. Now when you click the button or the items in the ListBox, you should see an animation in which these items first contract and then expand. That's another element of interactivity that you can add to your application if you desire.

NOTE

You can suppress the Tilt effect on any control by adding the local:TiltEffect.SuppressTilt="True" attribute to that control.

Other  
  •  Windows Phone 7 : Working with Controls and Themes - Understanding Frame and Page Navigation
  •  Windows Phone 7 : Working with Controls and Themes - Panorama and Pivot Controls
  •  Programming the Mobile Web : Widgets and Offline Webapps - Platforms (part 5) - Windows Mobile & BlackBerry
  •  Programming the Mobile Web : Widgets and Offline Webapps - Platforms (part 4) - Windows Mobile & BlackBerry
  •  Programming the Mobile Web : Widgets and Offline Webapps - Platforms (part 3) - webOS & Android
  •  Programming the Mobile Web : Widgets and Offline Webapps - Platforms (part 2) - iPhone, iPod, and iPad
  •  Programming the Mobile Web : Widgets and Offline Webapps - Platforms (part 1) - Symbian/Nokia
  •  Programming the Mobile Web : Widgets and Offline Webapps - Standards
  •  Mobile Application Security : BlackBerry Security - Networking
  •  Mobile Application Security : BlackBerry Security - Local Data Storage
  •  Themes on Windows Phone 7 Devices (part 2) - Changing the Theme & Detecting the Currently Selected Theme
  •  Themes on Windows Phone 7 Devices (part 1) - Applying a Theme
  •  Programming the Mobile Web : Mobile Widget Platforms
  •  Programming the Mobile Web : Geolocation and Maps - Showing a Map
  •  Mobile Application Security - BlackBerry Security - Permissions and User Controls (part 2)
  •  Mobile Application Security - BlackBerry Security - Permissions and User Controls (part 1) - RIM Controlled APIs
  •  Windows Phone 7 Development : Working with Controls and Themes - Introducing the Metro Design System
  •  Windows Phone 7 Development : WebBrowser Control - Saving Web Pages Locally
  •  Programming the Mobile Web : Geolocation and Maps - Detecting the Location (part 3)
  •  Programming the Mobile Web : Geolocation and Maps - Detecting the Location (part 2) - Google Gears
  •  
    Video
    Top 10
    Windows Server 2003 : Domain Name System - Command-Line Utilities
    Microsoft .NET : Design Principles and Patterns - From Principles to Patterns (part 2)
    Microsoft .NET : Design Principles and Patterns - From Principles to Patterns (part 1)
    Brother MFC-J4510DW - An Innovative All-In-One A3 Printer
    Computer Planet I7 Extreme Gaming PC
    All We Need To Know About Green Computing (Part 4)
    All We Need To Know About Green Computing (Part 3)
    All We Need To Know About Green Computing (Part 2)
    All We Need To Know About Green Computing (Part 1)
    Master Black-White Copying
    Most View
    Epic Moments in Sports (Part 1)
    iPhone 3D Programming : Blending and Augmented Reality - Blending Recipe
    HP X2301 : Micro Thin, Macro Sights
    Advanced ASP.NET : Understanding Caching
    Amateur Astronomy Applications (Part 1) - WorldWide Telescope, Stellarium
    How To Buy…SSD Drives (Part 2)
    Macro Marvel by Peiling Lee
    Under The Surface (Part 1)
    Microsoft .NET : Design Principles and Patterns - Object-Oriented Design (part 1) - Basic OOD Principles
    Hosting a Multi-Tenant Application on Windows Azure : Selecting a Single-Tenant or Multi-Tenant Architecture
    Google Nexus 4 - Features Of A High-End Smartphone For Half The Price
    Developing an SEO-Friendly Website: Content Delivery and Search Spider Control (part 2)
    SQL Server 2008 : Explaining Advanced Query Techniques - Managing Internationalization Considerations
    Frequently Asked Questions About UAC
    Windows Server 2008 : Harnessing the Power and Potential of FIM
    Parallel Programming with Microsoft .Net : Dynamic Task Parallelism - An Example
    Microsoft XNA Game Studio 3.0 : Displaying Images - Using Resources in a Game (part 3) - Sprite Drawing with SpriteBatch
    Windows Server 2003 : Active Directory - Understanding Operations Master Roles
    Windows 7 : Using Windows Defender (part 3) - Using Windows Defender Tools & Troubleshooting Windows Defender
    iOS 6 Beta Review (Part 1)