首发 手把手教你制作 Windows8 应用程序内部的 hubtile (动态瓷砖控件) MetroStyle(转)
http://blog.csdn.net/wangrenzhu2011/article/details/8175492 (转)
在metro 风格中 动态磁贴是他的精髓

在wp7 的开发中 我们可以使用hubtile 来制作类似效果
但是在 win8 中并不具备这个功能,
下面我们来通过扩展GridViewItem 来实现 PictureHubTile
- <GridViewItem
- x:Class="App1.HubTile"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="using:App1"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d"
- x:Name="gridViewItem"
- d:DesignHeight="150"
- d:DesignWidth="150">
- <GridViewItem.Resources>
- <Storyboard x:Name="UpperSecStoryboard">
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="SecImg">
- <SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="-150" KeySpline="0.29,0.88,0,1"/>
- </DoubleAnimationUsingKeyFrames>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="FirstImg">
- <SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="150" KeySpline="1,0,1,0"/>
- </DoubleAnimationUsingKeyFrames>
- </Storyboard>
- <Storyboard x:Name="UpperFirstStoryboard">
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="SecImg">
- <SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="0" KeySpline="1,0,1,0"/>
- </DoubleAnimationUsingKeyFrames>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="FirstImg">
- <SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="0" KeySpline="0.29,0.88,0,1"/>
- </DoubleAnimationUsingKeyFrames>
- </Storyboard>
- </GridViewItem.Resources>
- <Grid Width="{Binding Width, ElementName=gridViewItem}" Height="{Binding Height, ElementName=gridViewItem}">
- <Canvas x:Name="PART_LayoutRoot" >
- <StackPanel x:Name="PART_Panel">
- <Canvas
- Height="{Binding Height, ElementName=gridViewItem}"
- x:Name="FirstImg">
- <Grid x:Name="PART_FirstContent">
- <Image x:Name="Img1"
- Width="{Binding Width, ElementName=gridViewItem}"
- Height="{Binding Height, ElementName=gridViewItem}"
- Stretch="UniformToFill" VerticalAlignment="Center">
- </Image>
- </Grid>
- <Canvas.RenderTransform>
- <CompositeTransform/>
- </Canvas.RenderTransform>
- </Canvas>
- <Canvas
- x:Name="SecImg"
- Height="{Binding Height, ElementName=gridViewItem}">
- <Grid x:Name="SecGrid" Background="Red">
- <Image x:Name="Img2"
- Width="{Binding Width, ElementName=gridViewItem}"
- Height="{Binding Height, ElementName=gridViewItem}"
- Stretch="UniformToFill" VerticalAlignment="Center">
- </Image>
- </Grid>
- <Canvas.RenderTransform>
- <CompositeTransform/>
- </Canvas.RenderTransform>
- </Canvas>
- </StackPanel>
- </Canvas>
- <ContentPresenter Content="1111" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" x:Name="PART_Title" Margin="0,0,10,7" />
- </Grid>
- </GridViewItem>
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using Windows.Foundation;
- using Windows.Foundation.Collections;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Controls.Primitives;
- using Windows.UI.Xaml.Data;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Media.Animation;
- using Windows.UI.Xaml.Media.Imaging;
- using Windows.UI.Xaml.Navigation;
- using WinRTXamlToolkit.AwaitableUI;
- using WinRTXamlToolkit.Imaging;
- // “用户控件”项模板在 http://go.microsoft.com/fwlink/?LinkId=234236 上提供
- namespace App1
- {
- public sealed partial class HubTile : GridViewItem
- {
- #region propdp
- #region ImgList
- public List<string> ImgList
- {
- get { return (List<string>)GetValue(ImgListProperty); }
- set { SetValue(ImgListProperty, value); }
- }
- // Using a DependencyProperty as the backing store for ImgList. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty ImgListProperty =
- DependencyProperty.Register(
- "ImgList",
- typeof(List<string>),
- typeof(HubTile),
- new PropertyMetadata(null, OnImgListChanged));
- private static void OnImgListChanged(
- DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var target = (HubTile)d;
- }
- #endregion
- #endregion
- public HubTile()
- {
- this.InitializeComponent();
- DispatcherTimer timer = new DispatcherTimer();
- int index = 0;
- bool isFirst = true;
- Storyboard storySec = null;
- Storyboard storyFir = null;
- this.Loaded += ((sender, e) =>
- {
- storySec = Resources["UpperSecStoryboard"] as Storyboard;
- storyFir = Resources["UpperFirstStoryboard"] as Storyboard;
- var animation = storySec.Children[0] as DoubleAnimationUsingKeyFrames;
- var keyframe = animation.KeyFrames[0] as SplineDoubleKeyFrame;
- ((storySec.Children[1] as DoubleAnimationUsingKeyFrames).KeyFrames[0] as SplineDoubleKeyFrame).Value = this.Height;
- keyframe.Value = -this.Height;
- if (null != ImgList && ImgList.Count > 0)
- {
- var url = ImgList[0];
- BitmapImage _source = new BitmapImage(new Uri(url));
- this.Img1.Source = _source;
- timer.Start();
- }
- });
- Random r = new Random(Convert.ToInt32(DateTime.Now.Millisecond));
- var second = r.Next(2000, 6000);
- Debug.WriteLine(this.Name + "间隔时间:" + second);
- timer.Interval = TimeSpan.FromMilliseconds(second);
- timer.Tick += (async (o, b) =>
- {
- index++;
- var count = ImgList.Count;
- if (null != ImgList)
- {
- var url = ImgList[index % count];
- BitmapImage _source = new BitmapImage(new Uri(url));
- Debug.WriteLine(this.Name + "加载图片..." + url);
- if (isFirst)
- {
- this.Img2.Source = _source;
- isFirst = false;
- await storySec.BeginAsync();
- Canvas.SetZIndex(SecImg, 1);
- Canvas.SetZIndex(FirstImg, 2);
- }
- else
- {
- this.Img1.Source = _source;
- isFirst = true;
- await storyFir.BeginAsync();
- Canvas.SetZIndex(SecImg, 2);
- Canvas.SetZIndex(FirstImg, 1);
- }
- }
- });
- }
- }
- }
该样例代码中 我使用了awaitUI 来实现对动画执行的监控,
程序逻辑并不复杂,通过随机的timer 来切换图片 实现
开始菜单的效果
demo 稍后上传
最终效果图:

资源下载地址:http://download.csdn.net/detail/wangrenzhu2011/4760211
样例项目
首发 手把手教你制作 Windows8 应用程序内部的 hubtile (动态瓷砖控件) MetroStyle(转)的更多相关文章
- 手把手教你制作微信小程序,开源、免费、快速搞定
最近做了个"罗孚传车"的小程序 一时兴起,做了一个小程序,将个人收集的同汽车相关的行业资讯和学习资料,分享到小程序中,既作为历史资料保存,又提供给更多的人学习和了解,还能装一下:) ...
- 手把手教你制作AppPreview视频并上传到appStore进行审核
手把手教你制作AppPreview视频并上传到appStore进行审核 注意,你需要使用iMovie才能够制作AppPreview视频文件,用QuickTime录制的无效! 最终效果 1. 新建一个事 ...
- 手把手教你写Kafka Streams程序
本文从以下四个方面手把手教你写Kafka Streams程序: 一. 设置Maven项目 二. 编写第一个Streams应用程序:Pipe 三. 编写第二个Streams应用程序:Line Split ...
- PWA入门:手把手教你制作一个PWA应用
摘要: PWA图文教程 原文:PWA入门:手把手教你制作一个PWA应用 作者:MudOnTire Fundebug经授权转载,版权归原作者所有. 简介 Web前端的同学是否想过学习app开发,以弥补自 ...
- WPF 程序如何移动焦点到其他控件
原文:WPF 程序如何移动焦点到其他控件 WPF 中可以使用 UIElement.Focus() 将焦点设置到某个特定的控件,也可以使用 TraversalRequest 仅仅移动焦点.本文介绍如何在 ...
- C# 向程序新建的窗体中添加控件,控件需要先实例化,然后用controls.add添加到新的窗体中去
C# 向程序新建的窗体中添加控件,控件需要先实例化,然后用controls.add添加到新的窗体中去 Form settingForm = new Form(); setForm deviceSet ...
- 手把手教你玩微信小程序跳一跳
最近微信小程序火的半边天都红了,虽然不会写,但是至少也可以仿照网上大神开发外挂吧!下面手把手教妹纸们(汉纸们请自觉的眼观耳听)怎么愉快的在微信小游戏中获得高分. 废话不多说,咱们这就发车了!呸!咱们这 ...
- 手把手教你WEB套打程序开发
WEB套打可选方案不多,理想的更少,利用免费控件Lodop+JavaScript实现精确套打,算是较为经典的选择.这种方案其实比较简单,利用一个htm文件就可以实现模板设计过程,几乎是“空手套”式的开 ...
- 教你写一个Android可快速复用的小键盘输入控件
引子 在Android项目开发中特别是一些稍大型的项目,面对需求文档的时候你经常会发现很多地方用到了同样的组件,但是又略有不同.比如这个: 右边是一个小键盘输入板,左边当焦点不同的时候分别用右边的小键 ...
随机推荐
- Stanford机器学习---第三讲. 逻辑回归和过拟合问题的解决 logistic Regression & Regularization
原文:http://blog.csdn.net/abcjennifer/article/details/7716281 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...
- Android之开启手机系统自带铃声
/** * 开启手机系统自带铃声 */ private void startAlarm() { mMediaPlayer = MediaPlayer.create(this, getSystemDef ...
- Coursera台大机器学习课程笔记9 -- Logistic Regression
如果只想得到某种概率,而不是简单的分类,那么该如何做呢?在误差衡量问题上,如何选取误差函数这段很有意思. 接下来是如何最小化Ein,由于Ein是可凸优化的,所以采用的是梯度下降法:只要达到谷底,就找到 ...
- HDU 4435 charge-station () bfs图论问题
E - charge-station Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- Python fopen,open,和popen的区别
1. fopen 打开普通文件 带缓冲区撒点粉撒点粉阿桑地方 缓冲文件系统是借助文件结构体指针来对文件进行管理,通过文件指针来对文件进行访问,既可以读写字符.字符串.格式化数据,也可以读写二 ...
- Metasploit是一款开源的安全漏洞检测工具,
Metasploit是一款开源的安全漏洞检测工具,可以帮助安全和IT专业人士识别安全性问题,验证漏洞的缓解措施,并管理专家驱动的安全性进行评估,适合于需要核实漏洞的安全专家,同时也适合于强大进攻能力的 ...
- 1-2+3-4+5-6+7......+n的几种实现
本文的内容本身来自一个名校计算机生的一次面试经历,呵呵,没错,你猜对了,肯定 不是我 个人很喜欢这两道题,可能题目原本不止两道,当然,我这里这分析我很喜欢的两道. 1.写一个函数计算当参数为n(n很大 ...
- DOS命令符基本操作
怎么改变DOS默认路径 开始->所有程序->附件->命令提示符,在“命令提示符”上右键,选择“属性”,(或者在快捷方式上点击属性)会弹出一个“命令提示符 属性”对话框,可以通过修改该 ...
- css用标签选择器在本页写样式
<title>静夜思</title><style type="text/css">p{ color:#ff0000; font-size:2 ...
- spring+quartz报错:Table 'BANKSTEELERP_OLD.QRTZ_TRIGGERS' doesn't exist
spring3.2.8 + quartz2.2.1配置到application.xml中 org.springframework.beans.factory.BeanCreationException ...