Windows Phone-Tilt effect on HubTile and other Controls

Source: Internet
Author: User
Tags silverlight

In this article I will talk about creating tilt effect in different control in Windows Phone. implementing tilt effect on controls are easy but few controls like Hubtile, textblock don't create tilt effect itself. we need to little bit work around to achieve. in this article first we will look into how to create tilt effect on normal controls then we will discuss on how to put tilt effect on hubtile, textblock.

Let's write code:

Download Silverlight Windows Phone Toolkit

Step 1:Create a silverlight for Windows Phone project.

Step 2:Add reference of Microsoft. Phone. Controls. Toolkit. dll

Step 3:Add namespace of Microsoft. Phone. Controls. Toolkit in MainPage. xaml.

Xmlns: toolkit = "clr-namespace: Microsoft. Phone. Controls; assembly = Microsoft. Phone. Controls. Toolkit"

Step 4:Add below line in phone: PhoneApplicationPage element.

Toolkit

: TiltEffect. IsTiltEnabled = "True"

Step 5:Add a listbox and a button inside ContenPanel of MainPage. xaml.

<ListBox Margin = "20,280," Height = "80" FontSize = "28">
<ListBoxItem Content = "Item1"/>
<ListBoxItem Content = "Item2"/>
</ListBox>

<Button x: Name = "tiltEffect" Margin = "20,480, 430" Height = "80" Width = "" Content = "Tilt"/>

Step 5:Now run the application and on touch of listbox item and button you will notice tilt effect.

Step 6:To suppress tilt effect for a special item of ListBox or control we can use below code.

Toolkit

: TiltEffect. SuppressTilt = "True"

Step 7:Now replace code of Step 5 with below code and run the application, the highlighted code will suppress the tilt effect.

<ListBox Margin = "20,280," Height = "80" FontSize = "28">
<ListBoxItem Content = "Item1"Toolkit: TiltEffect. SuppressTilt= "True"/>
<ListBoxItem Content = "Item2"/>
</ListBox>

<Button x: Name = "tiltEffect"Toolkit: TiltEffect. SuppressTilt = "True"Margin = "20,480, 430" Height = "80" Width = "" Content = "Tilt"/>

Step 8:Now add a hubtile, textblock and image inside ContentPanel of MainPage. xaml.

<

Toolkit: HubTile Title = "UnFreezed Title" Background = "Maroon" x: Name = "hubTile1"/>

<

Image Source = "/TestTilt.png" Margin = "0" HorizontalAlignment = "Left" Height = "173" Width = "173" verticalignment = "top"/>

<

TextBlock Text = "Testing" Style = "{StaticResource PhoneTextExtraLargeStyle}" Height = "100" Margin = "200,-random, 12, 0"/>

Step 9:Now run the application again and you will notice tile effect won't work for hubtile, image and textblock.

Let's implement tilt effect for hubtile, image and textblock.

Step 10:Now create a class TiltableControl (Highlighted) which in MainPage. xaml. cs abve MainPage class.

Namespace

Windows_Phone ___ Tile_Effect
{
Public class TiltableControl:Grid
{
}

Public partial class MainPage: PhoneApplicationPage
{

Step 11:Add TiltableControl in TiltableItems like shown below in the MainPage constructor.

TiltEffect

. TiltableItems. Add (typeof (TiltableControl ));

Step 12:Add namespace like below in MainPage. xaml.

Xmlns: myTilt = "clr-namespace: Windows_Phone ___ Tile_Effect"

Step 13:Now wrap the hubtile, textblock and image control created in Step 8 with TiltableControl.

<MyTilt: TiltableControl>
<Image Source = "/TestTilt.png" Margin = "0" HorizontalAlignment = "Left" Height = "173" Width = "173" verticalignment = "top"/>
</MyTilt: TiltableControl>

<MyTilt: TiltableControl>
<TextBlock Text = "Testing" Style = "{StaticResource PhoneTextExtraLargeStyle}" Height = "100" Margin = "200,-average, 12, 0"/>
</MyTilt: TiltableControl>

<MyTilt: TiltableControl>
<Toolkit: HubTile Title = "UnFreezed Title" Background = "Maroon" x: Name = "hubTile1"/>
</MyTilt: TiltableControl>

Step 14:Now run the application, you will notice hubtile, image and textblock has tilteffect.

This ends the article of tilt effect in hubtile, image and other controls in Windows Phone.

LikeUs if you find this post useful. Thanks!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.