相信用过Windows Phone或者Windows 8/8.1/10的朋友对下面这张截图肯定不陌生。这就是通过SemanticZoom来实现的,当数据过多时,这种控件尤其适用。它有一个放大视图ZoomedInView和一个缩小试图ZoomedOutView,前者主要用来显示当前页面的详细信息,后者则致力于快速导航。

那么我就自己来动手实践咯,首先我们在XAML中添加大致的界面,就像画画要先画轮廓一样。

<Grid Name="grid1" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"><SemanticZoom x:Name="semanticZoom" VerticalAlignment="Center" HorizontalAlignment="Center">   <SemanticZoom.ZoomedOutView></SemanticZoom.ZoomedOutView><SemanticZoom.ZoomedInView></SemanticZoom.ZoomedInView></SemanticZoom></Grid>

然后分别在这两个视图中添加你想要加入的东西。这里的核心就是,ZoomedOutView和ZoomedInView都是使用的同一个CollectionViewSource对象作为自己的数据集的。而这个属性我们在上一节谈到过:【万里征程——Windows App开发】ListView&GridView之分组。

我们先把后台代码写好。我就像一篇那样装模作样写一个类吧^_^

    public class Alarm{public string Title { get; set; }public DateTime AlarmClockTime { get; set; }public string Description { get; set; }         }

然后用一个函数来添加一大堆数据……一大堆数据。

private Alarm[] AddAlarmData()
{return new Alarm[]{new Alarm {Title="Alarm 1",AlarmClockTime=globalTime.AddHours(17),Description="First Alarm for Study" },new Alarm {Title="Alarm 2",AlarmClockTime=globalTime.AddHours(2),Description="Second Alarm for Study" },new Alarm {Title="Alarm 3",AlarmClockTime=globalTime.AddHours(7),Description="Third Alarm for Study" },new Alarm {Title="Alarm 4",AlarmClockTime=globalTime.AddHours(4),Description="4th Alarm for Study" },new Alarm {Title="Alarm 5",AlarmClockTime=globalTime.AddHours(5),Description="First Alarm for Fun" },new Alarm {Title="Alarm 6",AlarmClockTime=globalTime.AddHours(1),Description="First Alarm for Fun" },new Alarm {Title="Alarm 7",AlarmClockTime=globalTime.AddHours(15),Description="Second Alarm for Fun" },new Alarm {Title="Alarm 8",AlarmClockTime=globalTime.AddHours(9),Description="Third Alarm for Fun" },new Alarm {Title="Alarm 9",AlarmClockTime=globalTime.AddHours(20),Description="4th Alarm for Fun" },new Alarm {Title="Alarm 10",AlarmClockTime=globalTime.AddHours(14),Description="Second Alarm for Sleep" },new Alarm {Title="Alarm 11",AlarmClockTime=globalTime.AddHours(9),Description="First Alarm for Sleep" }};
}

因为我们最后要把放大视图变成缩小视图,记得缩小视图上面有一些ABCD之类的字母么,这里我们用的是时间,就分成中午晚上等好啦。就通过下面这样的一个函数来搞定。其用了一个键值对,用time作为参数。后面再将这些数据筛选出来,绑定到新添加的CollectionViewSource中。至于gridView1和gridView2是即将添加到XAML中,这里可以先不填,一回再补上。

Func<int, string> SwitchTime = (time) =>
{if (time <= 10 && time >= 6)return "上午";else if (time > 10 && time < 14)return "中午";else if (time >= 14 && time <= 20)return "下午";elsereturn "晚上";
};
var varTime = from t in AddAlarmData()orderby t.AlarmClockTime.Hourgroup t by SwitchTime(t.AlarmClockTime.Hour);
CollectionViewSource collectionVS = new CollectionViewSource();
collectionVS.IsSourceGrouped = true;
collectionVS.Source = varTime;
this.gridView1.ItemsSource = collectionVS.View.CollectionGroups;
this.gridView2.ItemsSource = collectionVS.View;

我们先来写主视图(也就是放大视图)。

<GridView x:Name="gridView2" IsSwipeEnabled="True" HorizontalAlignment="Center" VerticalAlignment="Center" ScrollViewer.IsHorizontalScrollChainingEnabled="False" Width="1800" Height="1000"><GridView.ItemTemplate><DataTemplate><StackPanel Orientation="Horizontal" Margin="12" HorizontalAlignment="Left" Background="White"><TextBlock Text="{Binding Title}" TextWrapping="Wrap" Foreground="Red" FontFamily="Harrington" Width="150" Height="100" FontSize="26" FontWeight="Light"/><TextBlock Text="{Binding AlarmClockTime}" Foreground="Red" TextWrapping="Wrap" Width="150" Height="100" FontFamily="Harrington" FontSize="26" FontWeight="Light"/><TextBlock Text="{Binding Description}" Foreground="Red" TextWrapping="Wrap" Width="150" Height="100" FontFamily="Harrington" FontSize="26" FontWeight="Light"/></StackPanel></DataTemplate></GridView.ItemTemplate><GridView.ItemsPanel><ItemsPanelTemplate><ItemsWrapGrid MaximumRowsOrColumns="8"/></ItemsPanelTemplate></GridView.ItemsPanel><GridView.GroupStyle><GroupStyle><GroupStyle.HeaderTemplate><DataTemplate><TextBlock Text='{Binding Key}' Foreground="{StaticResource ApplicationForegroundThemeBrush}" Margin="12" FontSize="30" FontFamily="华文彩云" FontWeight="ExtraBold" /></DataTemplate></GroupStyle.HeaderTemplate></GroupStyle></GridView.GroupStyle>
</GridView>

相信大家都能看得懂,另外稍后我会在截图中添加一些注释的哦。然后是缩小视图。

<GridView Name="gridView1" Background="Wheat" ScrollViewer.IsHorizontalScrollChainingEnabled="False" HorizontalAlignment="Center" VerticalAlignment="Center" Width="600" Height="200"><GridView.ItemTemplate><DataTemplate><TextBlock Width="100" Height="100" Text="{Binding Group.Key}" FontFamily="华文行楷" FontWeight="Normal" FontSize="24" /></DataTemplate></GridView.ItemTemplate><GridView.ItemsPanel><ItemsPanelTemplate><ItemsWrapGrid ItemWidth="100" ItemHeight="100" MaximumRowsOrColumns="2"/></ItemsPanelTemplate></GridView.ItemsPanel><GridView.ItemContainerStyle><Style TargetType="GridViewItem"><Setter Property="Margin" Value="12" /><Setter Property="Padding" Value="3" /><Setter Property="BorderThickness" Value="1" /><Setter Property="Background" Value="Green"/></Style></GridView.ItemContainerStyle>
</GridView>

那么代码就到这里为止了,接下来自然就是截图了。

(这种图片如果看不清的话可以保存到电脑上再看。)

那么这篇博客就结束啦,再次感谢大家的支持!关于这些字体呢,大家可以看这篇:【万里征程——Windows App开发】使用华丽丽的字体。

为使本文得到斧正和提问,转载请注明出处:
http://blog.csdn.net/nomasp

版权声明:本文为 NoMasp柯于旺 原创文章,未经许可严禁转载!欢迎访问我的博客:http://blog.csdn.net/nomasp

转载于:https://my.oschina.net/nomasp/blog/503272

【万里征程——Windows App开发】SemanticZoom视图切换相关推荐

  1. 【万里征程——Windows App开发】应用栏

    基本的用法我们在 [万里征程--Windows App开发]页面布局和基本导航中已经讲过了,这里继续补充关于应用栏的更多用法. Icon 在之前的学习中,我们知道Icon属性中有很多很多系统预定义,但 ...

  2. 【万里征程——Windows App开发】开发准备

    操作系统及SDK 操作系统 如果打算开发Windows App,那么你的电脑就不能再用老旧的Windows 7了.推荐使用Windows 8.1.写这篇博客的时候,我用的操作系统是Windows 10 ...

  3. 【万里征程——Windows App开发】动态磁贴

    动态磁贴是什么,相信大家用了这么久的Windows 8/8.1/10早就非常了解了吧. 像什么小磁贴.中磁贴.宽磁贴.大磁贴,还有这里的应用商店Logo等,大家在下面根据不同的分辨率选择合适的图片就好 ...

  4. 【万里征程——Windows App开发】DatePickerFlyout、TimePickerFlyout的使用

    已经有挺长时间没有更新这个专栏了,不过刚才有网友私信问我一个问题现在就火速更新上一篇~ 这一篇讲解在WP上DataPickerFlyout和TimePickerFlyout的使用,但它们只能在WP上跑 ...

  5. 【万里征程——Windows App开发】控件大集合1

    添加控件的方式有多种,大家更喜欢哪一种呢? 1)使用诸如 Blend for Visual Studio 或 Microsoft Visual Studio XAML 设计器的设计工具. 2)在 Vi ...

  6. 【万里征程——Windows App开发】DatePickerTimepicker

    在前面我们走马观花地介绍了一大堆控件,其中自然也包括这DatePicker和TimePicker,那么稍微高级些的用法呢? 如果你想做一个关于健身.闹钟等的App,那么不可避免的会用到时间这些控件了. ...

  7. 【万里征程——Windows App开发】数据绑定——简单示例、更改通知、数据转换...

    简单的数据绑定示例 相比于理论,我更倾向于从实践中开始博客,尤其是对于数据绑定.那么,我们先来看看几个简单的例子. 1.数据绑定到TextBox 我们依旧使用前面的闹钟类来开始.在下面的代码中,我们有 ...

  8. 【万里征程——Windows App开发】使用Toast通知

    前面我们使用了 MessageDialog来作为弹窗,这里来介绍一个更加高大上的Toast通知. Toast通知本质上动力是由XML来提供的,一开始我还不相信不知道XML原来有这么大的威力.现在就来看 ...

  9. 【万里征程——Windows App开发】文件数据——文件选取器

    使用文件选取器保存文件 就我个人而言,还是非常喜欢使用文件选取器的,因为能够用自己的代码来调用系统的各种弹框. 在这个示例中,首先在XAML中添加一个Button和一个TextBlock,分别命名为b ...

最新文章

  1. linux epoll事件模型详解
  2. ​【Python基础】告别枯燥,60 秒学会一个 Python 小例子(文末下载)
  3. Chrome Elements 标签页 和 View Source 的显示为什么有差异
  4. 数学--数论--剩余系 与 完全剩余系 与 简化剩余系
  5. linux php cli 太多,【linux】php cli 处理能力到底有多强?
  6. python 打开exe获取窗口句柄_使用Python快速启动多个PC客户端
  7. AngularJS资源整理收集
  8. 软件测试技术教程徐光侠,软件测试技术教程徐光侠韦庆杰第十二章节自动测试工具QTP的使用.ppt...
  9. 人脸对齐—级联回归模型和深度学习模型
  10. Python 的RS485 串口通讯
  11. Django项目骨架与常见配置修改
  12. JZOJ5426. 【NOIP2017提高A组集训10.25】摘Galo
  13. 关于前端导出文件打不开的问题
  14. 青柠起始页样式书写+清新风格登录界面——Html+Css+JavaScript
  15. 按钮自动发光用html怎么弄,HTML+CSS+JS发光开关按钮
  16. 微商助理 防伪防窜货溯源代理授权查询系统源码
  17. 新闻发布系统,防火墙关了吗?
  18. 应用层、传输层、网络层常用协议
  19. matlab、C语言实现时域卷积运算
  20. matlab中文函数手册,函数 - MATLAB 系统中文帮助手册

热门文章

  1. 移动换H5 の 纯CSS3实现大转盘抽奖布局 by FungLeo
  2. 博才教育三校领导莅临湖南省智慧教育装备展示体验中心参观交流
  3. Python调用xbox手柄马达震动
  4. Beyond Compare 4 远程对比
  5. 任正非谈“咖啡杯”文化
  6. 测试用例编写练习(二)
  7. 十大众筹PC:硅谷新生代如何打造下一代计算机
  8. HDOJ 5144 NPY and shot 简单物理
  9. APT组织最喜欢的工具 Cobalt Strike (CS) 实战
  10. CISP证书的基本常识