Floating FB popout byF5debug

Learn Windows Phone 7 Development in 31 Days – Day 15 – Working with Tiles in WP7

 

Introduction:

In this article we are going to use how to use the Tile in our windows phone 7 development. In our earlier articles we have seen the Push Notifications and the different types of Notifications available. In this article we will see the different types of tile available and also see the step by step process on creating a tile for an application.

Tiles are nothing but  linking an application to the home screen with some options to update the status. Here we have 2 types of Tile development available

  • Application Tile – This type is used when the application is pinned to the Start screen by the user for easy accessing with the application Icon in the application list. Clicking on the tile will navigate directly to the application for easy accessibility  [more]
  • Secondary Tile – This type is basically created programmatically by the application based on the user interaction. This type of Tile will be used to navigate to the application and can be create only one instance. We need to use Create(Uri, ShellTileData) method to create a secondary tile.

Let us jump start to see the step by step process on how to create the Application Tile and the Secondary Tile one by one in detail.

Steps:

Open Visual Studio 2010 and create a new Silverlight for Windows Phone 7 application with a valid project name as shown in the screen below.

clip_image002

Let us first create an application tile and see the properties that are need to be assigned to create the tile. Once the page is opened in Visual Studio 2010 IDE just add 2 buttons to trigger the Application Tile and Secondary Tile one by one. Once we customized the design we can see the UI as shown in the screen below.

clip_image004

Now let us add the code to trigger the Application tile, to do that we need to go to the Application Tile button click event and write the below code.

Code Behind:

01

using System;

02

using System.Collections.Generic;

03

using System.Linq;

04

using System.Net;

05

using System.Windows;

06

using System.Windows.Controls;

07

using System.Windows.Documents;

08

using System.Windows.Input;

09

using System.Windows.Media;

10

using System.Windows.Media.Animation;

11

using System.Windows.Shapes;

12

using Microsoft.Phone.Controls;

13

using Microsoft.Phone.Shell;

14

namespace F5debugWp7Tiles

15

{

16

public partial class MainPage : PhoneApplicationPage

17

{

18

// Constructor

19

public MainPage()

20

{

21

InitializeComponent();

22

}

23

private void button1_Click(object sender, RoutedEventArgs e)

24

{

25

ShellTile AppShell = ShellTile.ActiveTiles.First();

26

StandardTileData AppTile = new StandardTileData();

27

AppTile.Title = "F5debug";

28

AppTile.BackgroundImage = new Uri("RedTile.jpg", UriKind.Relative);

29

AppTile.Count= 10;

30

AppTile.BackTitle = "F5Debug Back";

31

AppTile.BackBackgroundImage = new Uri("BlueTile.jpg", UriKind.Relative);

32

AppTile.BackContent=" This is Back Content";

33

AppShell.Update(AppTile);

34

}

clip_image006

Now we will check if the application is building and executing correctly and the Application Tile is working good on pinning the application to start. To check build and execute the application by pressing F5 directly and we can see the application loaded to the Windows Phone 7 Emulator as shown in the screen below.

clip_image008

Now click on the Application Tile button and we can see the application tile get created on the start screen. To check that first click on the Start button at the bottom and in the list view of the applications select our application F5debugWp7Tiles and select pin to start. Now go back to the main screen (Home) and we can see the tiles as shown in the screen below.

clip_image010

Now we are good with creating a Application Tile, let us start with creating a Secondary Tile. To start with first let us add a new page Page1.xaml and design it as shown in the screen below.

XAML Code:

01

<Grid x:Name="LayoutRoot" Background="Transparent">

02

<Grid.RowDefinitions>

03

<RowDefinition Height="Auto"/>

04

<RowDefinition Height="*"/>

05

</Grid.RowDefinitions>

06

<!--<span class="hiddenSpellError" pre="">TitlePanel</span> contains the name of the application and page title-->

07

<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">

08

<TextBlock x:Name="ApplicationTitle" Text="F5DEBUG WP7 TUTORIALS" Style="{StaticResource PhoneTextNormalStyle}"/>

09

<TextBlock x:Name="PageTitle" Text="Secondary Tiles" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>

10

</StackPanel>

11

<!--<span class="hiddenSpellError" pre="">ContentPanel</span> - place additional content here-->

12

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

13

<TextBlock Height="193" HorizontalAlignment="Left" Margin="71,146,0,0" Name="textBlock1" FontSize="36" TextWrapping="Wrap" Text="This is Secondary Tile Application" VerticalAlignment="Top" Width="293" />

14

</Grid>

15

</Grid>

clip_image012

Now navigate to the MainPage.XAML and add the below code to the second button click event (Secondary Tile). The below code will create the tile and will pass on to the Page1.xaml.

C# Code:

1

private void button2_Click(object sender, RoutedEventArgs e)

2

{

3

StandardTileData SecTitle = new StandardTileData();

4

SecTitle.Title = "F5Debug Sec Title";

5

SecTitle.BackgroundImage = new Uri("BlueTile.jpg", UriKind.Relative);

6

SecTitle.Count = 70;

7

var URINav = "/Page1.xaml?state=Sec Tile";

8

ShellTile.Create(new Uri(URINav, UriKind.Relative), SecTitle);

9

}

Now on the Page1.xaml we need to write our requirement if all we need to do some manipulation when clicking on the secondary tile. Here we are just showing the sample page on page navigation so we have not written any code on the OnNavigatedTo event as shown in the screen below.

C# Code:

1

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

2

{

3

base.OnNavigatedTo(e);

4

}

Now we are done with our code, just build and execute the project and we can see the screen with the 2 buttons as shown in the screen below.

clip_image014

Now click on the Secondary Tile and we can see the Secondary tile created as shown in the screen below.

clip_image016

Clicking on the secondary tile (F5Debug Sec Tile) will navigate to the Secondary Tile Page (Page1.xaml) as shown in the screen below.

clip_image018

Conclusion:

So in this article we have seen what is a Tile and how to create a basic tile and to assign the tile with the basic properties. Also we have seen how to create a Secondary tile and use it on navigation based on the purpose.

About Author: Karthikeyan Anbarasan, Microsoft MVP (Most Valuable Professional) in ASP.NET/IIS Architecture. He is the Founder and Chief Editor of the www.f5debug.net website and has authored books on Windows Phone and Business Intelligence(SSIS). He is also a Passionate Speaker and a Blogger on Microsoft Technologies.

You can Join Me On: Facebook, Twitter, Google Plus, LinkedIn

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Recent Posts

Random Posts

Most Viewed

URL Shortner

Create your own short urls!!!

Site Counter

free counters

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet. I have documented my personal experience on this blog.

Protected by Copyscape Web Plagiarism Finder

Site Meter