Working with the Windows Phone HubTile Events
published on: 10/6/2011 | Views: N/A | Tags: WP7Toolkit
by WindowsPhoneGeek
In this post I am going to talk about how to react to different HubTile events. Recently we received a lot of questions regarding working with HubTile events so that is why we decided to explain all this in a short post.
Before we begin it is recommended that you take a look at: Windows Phone HubTile in depth| Part1: key concepts and API
The problem?
It is not obvious what events the HubTile exposes and how to use them.
Why?
The problem is caused by the fact that the HubTile control itself does not define any events. Instead it inherits the basic framework events from the UIElement class.
Solutions?
To begin with lets first define a few HubTile instances in XAML:
<StackPanel>
<toolkit:HubTile x:Name="hubTile" Title="Tap Here" Message="This is HubTile message!" Margin="10"/>
<toolkit:HubTile x:Name="hubTile1" Source="wpglogo.png" Title="DoubleTap Here" Message="This is HubTile message!" Margin="10"/>
<toolkit:HubTile x:Name="hubTile2" Background="Green" Source="wpglogo.png" Title="Hold Here" Message="This is HubTile message!" Margin="10"/>
<toolkit:HubTile x:Name="hubTileNav" Title="London" GroupTag="Cities" Margin="10"/>
</StackPanel>
Example1:
Lets say that you want to navigate to another page when when the user presses a tile. In order to do this we have to subscribe to the "Tap" event:
this.hubTile.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(hubTile_Tap);
void hubTileNav_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Uri secondPageUri = new Uri("/SecondPage.xaml", UriKind.Relative);
this.NavigationService.Navigate(secondPageUri);
}
Example2:
This example demonstrates how to handle the Tap event.
this.hubTile.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(hubTile_Tap);
void hubTile_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
MessageBox.Show("Hub tile 1 was tapped");
}
Example3:
This example demonstrates how to handle the DoubleTap event.
this.hubTile1.DoubleTap += new EventHandler<System.Windows.Input.GestureEventArgs>(hubTile1_DoubleTap);
void hubTile1_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
{
MessageBox.Show("Hub tile 2 was double tapped");
}
Example4:
This example demonstrates how to handle the Hold event.
this.hubTile2.Hold += new EventHandler<System.Windows.Input.GestureEventArgs>(hubTile2_Hold);
void hubTile2_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
MessageBox.Show("Hub tile 3 was hold");
}
That was all about working with the basic HubTile events. The source code is available here:
I hope that the article was helpful.
You may also find interesting the following articles:
- Windows Phone HubTile in depth| Part1: key concepts and API
- Windows Phone HubTile in depth| Part2: Data Binding
- Windows Phone HubTile in depth| Part3: Freezing and Unfreezing tiles
- 21 WP7 Toolkit in Depth articles covering all controls
You can also follow us on Twitter @winphonegeek
Comments
Thank You
posted by: Ghanishth on 10/7/2011 8:19:50 AM
Thanks for this info.
Our Top Articles & Free books
- Our FREE e-book: "Windows Phone Toolkit In Depth" 2nd edition
- 400+ Windows Phone Development articles in our Article Index
- 21 WP7 Toolkit in Depth articles covering all controls
- 12 WP7 Coding4Fun Toolkit in Depth articles covering all controls
- Performance Tips when creating WP7 apps
- Creating a WP7 Custom Control in 7 Steps
- WP7 working with VisualStates: How to make a ToggleSwitch from CheckBox
- What makes a WP7 App successful
- Creating theme friendly UI in WP7 using OpacityMask
- Implementing Windows Phone 7 DataTemplateSelector and CustomDataTemplateSelector
- All about Splash Screens in WP7 – Creating animated Splash Screen
- Getting Started with Unit Testing in Silverlight for WP7
- WP7 WatermarkedTextBox custom control
Our Top Tips & Samples
- All about WP7 Isolated Storage series
- WP7 Dynamically Generating DataTemplate in code
- 5 tips for a successful WP7 Marketplace submission
- WP7: Navigating to a page in different assembly
- WP7 ContextMenu: answers to popular questions
- WP7 ListBox: answers to popular questions
- WP7 working with Images: Content vs Resource build action
- WP7 Element Binding samples
- WP7 working with XML: reading, filtering and databinding
- Drawing in WP7: #2 Drawing shapes with finger
- WP7 TextBox Light theme problems - the solution
- Changing the WP7 Panorama Background Image dynamically with Animation
