How to Programmatically Switch between the HubTile Visual States
In this post I am going to talk about how to programmatically switch between different HubTile Visual States. Since the HubTile does not expose any API for changing / switching between its visual states manually it is not obvious how you can do that. However, the solution is pretty simple: you just need to use the VisualStateManager class which manages states and the logic for transitioning between states of controls.
For reference take a look at the official MSDN Documentation.
To begin with, lets first create a new Windows Phone application project and add a reference toMicrosoft.Phone.Controls.Toolkit.dll.
NOTE: For more information about the HubTile control take a look at:
- "Silverlight for Windows Phone Toolkit In Depth" FREE e-book
- Windows Phone HubTile in depth| Part1: key concepts and API
Step1. Add the following code in MainPage.xaml:
1
2
3
4
|
< phone:PhoneApplicationPage x:Class = "HubTileDemo.MainPage" ... xmlns:toolkit = "clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" > |
1
2
3
4
5
6
7
8
|
< StackPanel x:Name = "ContentPanel" Grid.Row = "1" Margin = "12,0,12,0" Orientation = "Vertical" > < toolkit:HubTile x:Name = "hubTile" Background = "Green" Source = "wpglogo.png" Title = "Hold Here" Message = "This is HubTile message!" Margin = "10" /> < Button x:Name = "btnGoToExpanded" Content = " Go To Expanded State" Click = "btnGoToExpanded_Click" /> < Button x:Name = "btnGoToSemiexpanded" Content = "Go To Semiexpanded State" Click = "btnGoToSemiexpanded_Click" /> < Button x:Name = "btnGoToFlipped" Content = "Go To Flipped State" Click = "btnGoToFlipped_Click" /> < Button x:Name = "btnGoToCollapsed" Content = "Go To Collapsed State" Click = "btnGoToCollapsed_Click" /> </ StackPanel > |
Step2. Set the HubTile "IsFrozen" property to true in order to prevent the HubTile Visual State from being changed automatically. Add the following code in MainPage.xaml.cs:
1
2
3
4
5
6
|
public MainPage() { InitializeComponent(); this .hubTile.IsFrozen = true ; } |
Step3. Go To Expanded State implementation:
1
2
3
4
|
private void btnGoToExpanded_Click( object sender, RoutedEventArgs e) { VisualStateManager.GoToState( this .hubTile, "Expanded" , true ); } |
Step4. Go To Semiexpanded State implementation:
1
2
3
4
|
private void btnGoToSemiexpanded_Click( object sender, RoutedEventArgs e) { VisualStateManager.GoToState( this .hubTile, "Semiexpanded" , true ); } |
Step5. Go To Flipped State implementation:
1
2
3
4
|
private void btnGoToFlipped_Click( object sender, RoutedEventArgs e) { VisualStateManager.GoToState( this .hubTile, "Flipped" , true ); } |
Step6. Go To Collapsed State implementation:
1
2
3
4
|
private void btnGoToCollapsed_Click( object sender, RoutedEventArgs e) { VisualStateManager.GoToState( this .hubTile, "Collapsed" , true ); } |
That was all about programmatically switching between the different HubTile Visual States. The source code is available here:
I hope that the article was helpful.
You may also find interesting the following articles:
- "Silverlight for Windows Phone Toolkit In Depth" FREE e-book
- Working with the Windows Phone HubTile Events
- 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
You can also follow us on Twitter: @winphonegeekfor Windows Phone; @winrtgeekfor Windows 8 / WinRT
Comments
Thanks again
posted by: Steven on 10/15/2011 6:18:40 PM
Thanks again! Very useful for me!
How to Switch on dynamically created HubTiles?
posted by: MSiccDev on 1/30/2012 1:24:46 PM
This works fine with a single HubTile.
But how can I do this if I add my HubTiles as DataTemplate to a ListBox?
The VisualStateManager does not recognize the HubTile as control, and returns alwas null.
Anyone an idea?
Programatically adding and animating
posted by: Nate Radebaugh on 12/21/2012 8:51:14 PM
If you are going to be controlling the states of a HubTile you have programatically added, you must do it after the HubTile is loaded. For instance:
HubTile tile = new HubTile();
tile.Title = "Title";
tile.Message = "Message";
tile.Loaded += tile_Loaded;
And then have the event handler perform the settings: (for example)
void tile_Loaded(object sender, RoutedEventArgs e)
{
HubTile tile = (HubTile)sender;
string setState = "Semiexpanded";
// set the tile's state
VisualStateManager.GoToState(tile, setState, true);
tile.IsFrozen = true;
}
Hope this helps someone else, took me a while to figure out where I was going wrong since the VisualStateManager.GoToState() does nothing and returns false if it doesn't know the state you send it, which it never knows before the HubTile is Loaded.
How to Programmatically Switch between the HubTile Visual States的更多相关文章
- 零元学Expression Blend 4 - Chapter 33 简单轻松的学会如何使用Visual States(下)
原文:零元学Expression Blend 4 - Chapter 33 简单轻松的学会如何使用Visual States(下) 上篇提到了Visual State Manager中文翻译为视觉状态 ...
- 零元学Expression Blend 4 - Chapter 32 简单轻松的学会如何使用Visual States(上)
原文:零元学Expression Blend 4 - Chapter 32 简单轻松的学会如何使用Visual States(上) Visual State Manager中文翻译为视觉状态管理器,这 ...
- Visual Studio创建跨平台移动应用_02.Cordova Extension
1简介 本章节是关于Visual Studio Tools for Apache Cordova的,目前此产品只发布了预览版.Visual Studio for Apache Cordova帮助熟悉V ...
- 使用 Cordova+Visual Studio 创建跨平台移动应用(1)
1简介 本章节是关于Visual Studio Tools for Apache Cordova的,目前此产品只发布了预览版.Visual Studio for Apache Cordova帮助熟悉V ...
- 论文笔记:Visual Semantic Navigation Using Scene Priors
Visual Semantic Navigation Using Scene Priors 2018-10-21 19:39:26 Paper: https://arxiv.org/pdf/1810 ...
- Expression Blend实例中文教程(11) - 视觉管理器快速入门Visual State Manager(VSM)
Visual State Manager,中文又称视觉状态管理器(简称为VSM),是Silverlight 2中引进的一个概念.通过使用VSM,开发人员和设计人员可以轻松的改变项目控件的视觉效果,在项 ...
- Expression Blend实例中文教程(11) - 视觉管理器快速入门Visual State Manager(VSM)
Expression Blend实例中文教程(11) - 视觉管理器快速入门Visual State Manager(V 时间:2010-04-12 16:06来源:SilverlightChina. ...
- Chapter 20: Diagnostics
WHAT'S IN THIS CHAPTER?n Code contractsn Tracingn Event loggingn Performance monitoringWROX.COM CODE ...
- UWP VirtualizedVariableSizedGridView 支持可虚拟化可变大小Item的View(二)
上篇UWP VirtualizedVariableSizedGridView 支持可虚拟化可变大小Item的View(一) 讲到该控件的需要和设计过程. 这篇讲讲开发过程中一些重要问题解决. 1.支持 ...
随机推荐
- 组合数学or not ---- n选k有重
模板问题: 1. 取物品 (comb.pas/c/cpp) [问题描述] 现在有n个物品(有可能相同),请您编程计算从中取k个有多少种不同的取法.[输入] 输入文件有两行,第一行包含两个整数n,k(2 ...
- FastCgi与PHP-fpm之间是个什么样的关系
刚开始对这个问题我也挺纠结的,看了<HTTP权威指南>后,感觉清晰了不少. 首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的,方便CGI程序的编写者. ...
- mysql中的unsigned
unsigned 既为非负数,用此类型可以增加数据长度! 例如如果 tinyint最大是127,那 tinyint unsigned 最大 就可以到 127 * ...
- MySQL数据库索引的4大类型以及相关的索引创建
以下的文章主要介绍的是MySQL数据库索引类型,其中包括普通索引,唯一索引,主键索引与主键索引,以及对这些索引的实际应用或是创建有一个详细介绍,以下就是文章的主要内容描述. (1)普通索引 这是最基本 ...
- jQuery Ajax 操作函数
jQuery Ajax 操作函数 jQuery 库拥有完整的 Ajax 兼容套件.其中的函数和方法允许我们在不刷新浏览器的情况下从服务器加载数据. 函数 描述 jQuery.ajax() 执行异步 H ...
- php-fpm 进程管理
2015年2月26日 15:40:15 先查找 PHP-FPM 的进程号 ps -ef | grep php-fpm root Feb12 ? :: php-fpm: master process ( ...
- Java for LeetCode 023 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 解 ...
- 【回溯】图的m着色问题
问题 C: [回溯]图的m着色问题 时间限制: 1 Sec 内存限制: 128 MB提交: 1 解决: 1[提交][状态][讨论版] 题目描述 给定无向连通图G=(V, E)和m种不同的颜色,用这 ...
- Interger 与 int
int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...
- php 获取当前时间
<?php echo $showtime=date("Y-m-d H:i:s");?>