http://blog.csdn.net/wangrenzhu2011/article/details/8175492 (转)

在metro 风格中 动态磁贴是他的精髓

在wp7 的开发中 我们可以使用hubtile 来制作类似效果

但是在 win8 中并不具备这个功能,

下面我们来通过扩展GridViewItem 来实现  PictureHubTile

  1. <GridViewItem
  2. x:Class="App1.HubTile"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:App1"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d"
  9. x:Name="gridViewItem"
  10. d:DesignHeight="150"
  11. d:DesignWidth="150">
  12. <GridViewItem.Resources>
  13. <Storyboard x:Name="UpperSecStoryboard">
  14. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="SecImg">
  15. <SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="-150" KeySpline="0.29,0.88,0,1"/>
  16. </DoubleAnimationUsingKeyFrames>
  17. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="FirstImg">
  18. <SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="150" KeySpline="1,0,1,0"/>
  19. </DoubleAnimationUsingKeyFrames>
  20. </Storyboard>
  21. <Storyboard x:Name="UpperFirstStoryboard">
  22. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="SecImg">
  23. <SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="0" KeySpline="1,0,1,0"/>
  24. </DoubleAnimationUsingKeyFrames>
  25. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="FirstImg">
  26. <SplineDoubleKeyFrame KeyTime="0:0:1.2" Value="0" KeySpline="0.29,0.88,0,1"/>
  27. </DoubleAnimationUsingKeyFrames>
  28. </Storyboard>
  29. </GridViewItem.Resources>
  30. <Grid Width="{Binding Width, ElementName=gridViewItem}" Height="{Binding Height, ElementName=gridViewItem}">
  31. <Canvas x:Name="PART_LayoutRoot" >
  32. <StackPanel x:Name="PART_Panel">
  33. <Canvas
  34. Height="{Binding Height, ElementName=gridViewItem}"
  35. x:Name="FirstImg">
  36. <Grid  x:Name="PART_FirstContent">
  37. <Image x:Name="Img1"
  38. Width="{Binding Width, ElementName=gridViewItem}"
  39. Height="{Binding Height, ElementName=gridViewItem}"
  40. Stretch="UniformToFill" VerticalAlignment="Center">
  41. </Image>
  42. </Grid>
  43. <Canvas.RenderTransform>
  44. <CompositeTransform/>
  45. </Canvas.RenderTransform>
  46. </Canvas>
  47. <Canvas
  48. x:Name="SecImg"
  49. Height="{Binding Height, ElementName=gridViewItem}">
  50. <Grid x:Name="SecGrid" Background="Red">
  51. <Image x:Name="Img2"
  52. Width="{Binding Width, ElementName=gridViewItem}"
  53. Height="{Binding Height, ElementName=gridViewItem}"
  54. Stretch="UniformToFill" VerticalAlignment="Center">
  55. </Image>
  56. </Grid>
  57. <Canvas.RenderTransform>
  58. <CompositeTransform/>
  59. </Canvas.RenderTransform>
  60. </Canvas>
  61. </StackPanel>
  62. </Canvas>
  63. <ContentPresenter Content="1111" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" x:Name="PART_Title" Margin="0,0,10,7" />
  64. </Grid>
  65. </GridViewItem>
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using Windows.Foundation;
  8. using Windows.Foundation.Collections;
  9. using Windows.UI.Xaml;
  10. using Windows.UI.Xaml.Controls;
  11. using Windows.UI.Xaml.Controls.Primitives;
  12. using Windows.UI.Xaml.Data;
  13. using Windows.UI.Xaml.Input;
  14. using Windows.UI.Xaml.Media;
  15. using Windows.UI.Xaml.Media.Animation;
  16. using Windows.UI.Xaml.Media.Imaging;
  17. using Windows.UI.Xaml.Navigation;
  18. using WinRTXamlToolkit.AwaitableUI;
  19. using WinRTXamlToolkit.Imaging;
  20. // “用户控件”项模板在 http://go.microsoft.com/fwlink/?LinkId=234236 上提供
  21. namespace App1
  22. {
  23. public sealed partial class HubTile : GridViewItem
  24. {
  25. #region propdp
  26. #region ImgList
  27. public List<string> ImgList
  28. {
  29. get { return (List<string>)GetValue(ImgListProperty); }
  30. set { SetValue(ImgListProperty, value); }
  31. }
  32. // Using a DependencyProperty as the backing store for ImgList.  This enables animation, styling, binding, etc...
  33. public static readonly DependencyProperty ImgListProperty =
  34. DependencyProperty.Register(
  35. "ImgList",
  36. typeof(List<string>),
  37. typeof(HubTile),
  38. new PropertyMetadata(null, OnImgListChanged));
  39. private static void OnImgListChanged(
  40. DependencyObject d, DependencyPropertyChangedEventArgs e)
  41. {
  42. var target = (HubTile)d;
  43. }
  44. #endregion
  45. #endregion
  46. public HubTile()
  47. {
  48. this.InitializeComponent();
  49. DispatcherTimer timer = new DispatcherTimer();
  50. int index = 0;
  51. bool isFirst = true;
  52. Storyboard storySec = null;
  53. Storyboard storyFir = null;
  54. this.Loaded += ((sender, e) =>
  55. {
  56. storySec = Resources["UpperSecStoryboard"] as Storyboard;
  57. storyFir = Resources["UpperFirstStoryboard"] as Storyboard;
  58. var animation = storySec.Children[0] as DoubleAnimationUsingKeyFrames;
  59. var keyframe = animation.KeyFrames[0] as SplineDoubleKeyFrame;
  60. ((storySec.Children[1] as DoubleAnimationUsingKeyFrames).KeyFrames[0] as SplineDoubleKeyFrame).Value = this.Height;
  61. keyframe.Value = -this.Height;
  62. if (null != ImgList && ImgList.Count > 0)
  63. {
  64. var url = ImgList[0];
  65. BitmapImage _source = new BitmapImage(new Uri(url));
  66. this.Img1.Source = _source;
  67. timer.Start();
  68. }
  69. });
  70. Random r = new Random(Convert.ToInt32(DateTime.Now.Millisecond));
  71. var second = r.Next(2000, 6000);
  72. Debug.WriteLine(this.Name + "间隔时间:" + second);
  73. timer.Interval = TimeSpan.FromMilliseconds(second);
  74. timer.Tick += (async (o, b) =>
  75. {
  76. index++;
  77. var count = ImgList.Count;
  78. if (null != ImgList)
  79. {
  80. var url = ImgList[index % count];
  81. BitmapImage _source = new BitmapImage(new Uri(url));
  82. Debug.WriteLine(this.Name + "加载图片..." + url);
  83. if (isFirst)
  84. {
  85. this.Img2.Source = _source;
  86. isFirst = false;
  87. await storySec.BeginAsync();
  88. Canvas.SetZIndex(SecImg, 1);
  89. Canvas.SetZIndex(FirstImg, 2);
  90. }
  91. else
  92. {
  93. this.Img1.Source = _source;
  94. isFirst = true;
  95. await storyFir.BeginAsync();
  96. Canvas.SetZIndex(SecImg, 2);
  97. Canvas.SetZIndex(FirstImg, 1);
  98. }
  99. }
  100. });
  101. }
  102. }
  103. }

该样例代码中 我使用了awaitUI 来实现对动画执行的监控,

程序逻辑并不复杂,通过随机的timer 来切换图片 实现

开始菜单的效果

demo 稍后上传

最终效果图:

资源下载地址:http://download.csdn.net/detail/wangrenzhu2011/4760211

样例项目

首发 手把手教你制作 Windows8 应用程序内部的 hubtile (动态瓷砖控件) MetroStyle(转)的更多相关文章

  1. 手把手教你制作微信小程序,开源、免费、快速搞定

    最近做了个"罗孚传车"的小程序 一时兴起,做了一个小程序,将个人收集的同汽车相关的行业资讯和学习资料,分享到小程序中,既作为历史资料保存,又提供给更多的人学习和了解,还能装一下:) ...

  2. 手把手教你制作AppPreview视频并上传到appStore进行审核

    手把手教你制作AppPreview视频并上传到appStore进行审核 注意,你需要使用iMovie才能够制作AppPreview视频文件,用QuickTime录制的无效! 最终效果 1. 新建一个事 ...

  3. 手把手教你写Kafka Streams程序

    本文从以下四个方面手把手教你写Kafka Streams程序: 一. 设置Maven项目 二. 编写第一个Streams应用程序:Pipe 三. 编写第二个Streams应用程序:Line Split ...

  4. PWA入门:手把手教你制作一个PWA应用

    摘要: PWA图文教程 原文:PWA入门:手把手教你制作一个PWA应用 作者:MudOnTire Fundebug经授权转载,版权归原作者所有. 简介 Web前端的同学是否想过学习app开发,以弥补自 ...

  5. WPF 程序如何移动焦点到其他控件

    原文:WPF 程序如何移动焦点到其他控件 WPF 中可以使用 UIElement.Focus() 将焦点设置到某个特定的控件,也可以使用 TraversalRequest 仅仅移动焦点.本文介绍如何在 ...

  6. C# 向程序新建的窗体中添加控件,控件需要先实例化,然后用controls.add添加到新的窗体中去

    C# 向程序新建的窗体中添加控件,控件需要先实例化,然后用controls.add添加到新的窗体中去 Form settingForm = new Form(); setForm deviceSet ...

  7. 手把手教你玩微信小程序跳一跳

    最近微信小程序火的半边天都红了,虽然不会写,但是至少也可以仿照网上大神开发外挂吧!下面手把手教妹纸们(汉纸们请自觉的眼观耳听)怎么愉快的在微信小游戏中获得高分. 废话不多说,咱们这就发车了!呸!咱们这 ...

  8. 手把手教你WEB套打程序开发

    WEB套打可选方案不多,理想的更少,利用免费控件Lodop+JavaScript实现精确套打,算是较为经典的选择.这种方案其实比较简单,利用一个htm文件就可以实现模板设计过程,几乎是“空手套”式的开 ...

  9. 教你写一个Android可快速复用的小键盘输入控件

    引子 在Android项目开发中特别是一些稍大型的项目,面对需求文档的时候你经常会发现很多地方用到了同样的组件,但是又略有不同.比如这个: 右边是一个小键盘输入板,左边当焦点不同的时候分别用右边的小键 ...

随机推荐

  1. 一个csrf实例漏洞挖掘带你了解什么是csrf

    [-]CSRF是个什么鬼? |___简单的理解: |----攻击者盗用了你的身份,以你的名义进行某些非法操作.CSRF能够使用你的账户发送邮件,获取你的敏感信息,甚至盗走你的财产. |___CSRF攻 ...

  2. 2.7 编程之美--最大公约数的3种解法[efficient method to solve gcd problem]

    [本文链接] http://www.cnblogs.com/hellogiser/p/efficient-method-to-solve-gcd-problem.html [题目] 求两个正整数的最大 ...

  3. Java中Set集合的使用

    除了List之外,Set集合接口也经常使用,Set接口中存放的元素是无序的并且是不可重复的,因此被称为数据集: Set接口因为是无序的,所以没有提供像List一样的set方法来修改元素,查找,添加.删 ...

  4. (原创)Python文件与文件系统系列(5)——stat模块

    stat模块中定义了许多的常量和函数,可以帮助解释 os.stat().os.fstat().os.lstat()等函数返回的 st_result 类型的对象. 通常使用 os.path.is*() ...

  5. 利用 Avisynth 2.5.8 的 ColorKeyMask 功能实现视频抠像

    下载安装Avisynth 2.5.8 + 下载安装 FFMpeg 编写 Avisynth 脚本 mating.avs ----------------------------------------- ...

  6. 利用 FFmpeg 和 ImageMagick, AVI 转 GIF(不失真)

    利用[TMPGEnc 4.0 XPress] 或 [TMPGEnc Video Mastering Works 5] 生成 AVI 这个视频编辑软件,可对每个帧进行操作 1.生成每个帧的 PNG ff ...

  7. HDU 1003 Max Sum

    Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  8. MST:Conscription(POJ 3723)

      男女搭配,干活不累 题目大意:需要招募女兵和男兵,每一个人都的需要花费1W元的招募费用,但是如果有一些人之间有亲密的关系,那么就会减少一定的价钱,如果给出1~9999的人之间的亲密关系,现在要你求 ...

  9. javascript 中string 型数据转换成int类型

    var str1 = "1234";var str2 = "1234";number = parseInt(str1); number就是int型 str1+s ...

  10. mybatis配置文件xml中插入新数据

    初用mybatis,发现很好的一个操作数据库的框架,里面有一些小技巧,挺简单,很实用,记录一下: mybatis的插入语句: <insert id="insertAsset" ...