[源码下载]

背水一战 Windows 10 (55) - 控件(集合类): SemanticZoom, ISemanticZoomInformation

作者:webabcd

介绍
背水一战 Windows 10 之 控件(集合类)

  • SemanticZoom
  • ISemanticZoomInformation

示例
1、SemanticZoom 的示例
Controls/CollectionControl/SemanticZoomDemo/SemanticZoomDemo.xaml

  1. <Page
  2. x:Class="Windows10.Controls.CollectionControl.SemanticZoomDemo.SemanticZoomDemo"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:Windows10.Controls.CollectionControl.SemanticZoomDemo"
  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.  
  10. xmlns:common="using:Windows10.Common">
  11.  
  12. <Grid Background="Transparent">
  13.  
  14. <StackPanel Orientation="Horizontal" Margin="5" VerticalAlignment="Top">
  15. <Button Name="btnToggleActiveView" Content="ToggleActiveView" Click="btnToggleActiveView_Click" />
  16. <TextBlock Name="lblMsg" Margin="10 0 0 0" />
  17. </StackPanel>
  18.  
  19. <!--
  20. SemanticZoom - SemanticZoom 控件
  21. IsZoomOutButtonEnabled - 是否显示用于切换视图的按钮(在 ZoomedInView 时,右下角会有个小按钮),默认值为 false
  22. ZoomedInView - 放大后的视图(需要实现 ISemanticZoomInformation 接口)
  23. ZoomedOutView - 缩小后的视图(需要实现 ISemanticZoomInformation 接口)
  24. IsZoomedInViewActive - ZoomedInView 视图是否为当前的活动视图,默认值为 true
  25. CanChangeViews - 是否可以在两个视图之间切换(如果禁止的话则用户将无法切换视图,程序通过 IsZoomedInViewActive 或 ToggleActiveView() 来切换的话则会抛出异常),默认值为 true
  26.  
  27. 如果需要通过缩放手势来切换 ZoomedInView 和 ZoomedOutView 的话,别忘了设置 ScrollViewer.ZoomMode="Enabled"
  28.  
  29. 注:
  30. 1、ListViewBase 实现了 ISemanticZoomInformation 接口,其通过绑定 CollectionViewSource 数据即可使 SemanticZoom 中的两个视图进行有关联的切换
  31. 2、以下以 ListViewBase 和 SemanticZoom 和 CollectionViewSource 相结合为例,说明其行为
  32. a) ZoomedInView 用于显示全部数据,包括组标题和每组的详细数据,点击组标题会进入到 ZoomedOutView 视图
  33. b) ZoomedOutView 用于只显示组标题,单击组标题会进入到 ZoomedInView 视图,并自动定位到对应的组
  34. 3、关于如何自定义 ISemanticZoomInformation 实现,请参见 /Controls/CollectionControl/SemanticZoomDemo/ISemanticZoomInformationDemo.xaml
  35. -->
  36.  
  37. <SemanticZoom Name="semanticZoom" Margin="5 50 5 5"
  38. ScrollViewer.ZoomMode="Enabled"
  39. IsZoomOutButtonEnabled="True" IsZoomedInViewActive="False" CanChangeViews="True">
  40.  
  41. <SemanticZoom.ZoomedInView>
  42. <GridView x:Name="gridViewDetails" Margin="5" ItemsSource="{x:Bind MyData.View}">
  43. <GridView.ItemTemplate>
  44. <DataTemplate x:DataType="common:NavigationModel">
  45. <Grid Width="120" Background="Orange">
  46. <TextBlock TextWrapping="Wrap" Text="{x:Bind Title}" />
  47. </Grid>
  48. </DataTemplate>
  49. </GridView.ItemTemplate>
  50. <GridView.GroupStyle>
  51. <GroupStyle>
  52. <GroupStyle.HeaderTemplate>
  53. <DataTemplate x:DataType="common:NavigationModel">
  54. <TextBlock Text="{x:Bind Title}" />
  55. </DataTemplate>
  56. </GroupStyle.HeaderTemplate>
  57. </GroupStyle>
  58. </GridView.GroupStyle>
  59. </GridView>
  60. </SemanticZoom.ZoomedInView>
  61.  
  62. <SemanticZoom.ZoomedOutView>
  63. <GridView x:Name="gridViewSummary" Margin="5" ItemsSource="{x:Bind MyData.View.CollectionGroups}">
  64. <GridView.ItemTemplate>
  65. <DataTemplate>
  66. <Grid Background="Orange" Width="100" Height="100">
  67. <!--
  68. 上下文数据为 ICollectionViewGroup 类型,其 Group 属性保存着组对象(本例中 Group 就是每组的 NavigationModel 类型的对象)
  69. ListViewBase 实现了 ISemanticZoomInformation 接口,其在 StartViewChangeTo(SemanticZoomLocation source, SemanticZoomLocation destination) 时,通过 source.Item 获取到的是一个 ICollectionViewGroup 类型的数据,其有两个属性:Group 和 GroupItems。关于 ISemanticZoomInformation 接口请参见:/Controls/CollectionControl/SemanticZoomDemo/MyFlipView.cs
  70. -->
  71. <TextBlock TextWrapping="Wrap" Text="{Binding Group.Title}" />
  72. </Grid>
  73. </DataTemplate>
  74. </GridView.ItemTemplate>
  75. </GridView>
  76. </SemanticZoom.ZoomedOutView>
  77.  
  78. </SemanticZoom>
  79. </Grid>
  80. </Page>

Controls/CollectionControl/SemanticZoomDemo/SemanticZoomDemo.xaml.cs

  1. /*
  2. * SemanticZoom - SemanticZoom 控件(继承自 Control, 请参见 /Controls/BaseControl/ControlDemo/)
  3. * ToggleActiveView() - 在 ZoomedInView, ZoomedOutView 两个视图之间切换
  4. * ViewChangeStarted - 视图切换开始时触发的事件
  5. * ViewChangeCompleted - 视图切换完成时触发的事件
  6. *
  7. *
  8. * CollectionViewSource - 对集合数据启用分组支持
  9. * Source - 数据源
  10. * View - 获取视图对象,返回一个实现了 ICollectionView 接口的对象
  11. * IsSourceGrouped - 数据源是否是一个被分组的数据
  12. * ItemsPath - 数据源中,子数据集合的属性名称
  13. *
  14. * ICollectionView - 支持数据分组是 ICollectionView 的作用之一
  15. * CollectionGroups - 组数据集合
  16. */
  17.  
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Xml.Linq;
  21. using Windows.UI.Xaml;
  22. using Windows.UI.Xaml.Controls;
  23. using Windows.UI.Xaml.Data;
  24. using Windows10.Common;
  25.  
  26. namespace Windows10.Controls.CollectionControl.SemanticZoomDemo
  27. {
  28. public sealed partial class SemanticZoomDemo : Page
  29. {
  30. public CollectionViewSource MyData
  31. {
  32. get
  33. {
  34. XElement root = XElement.Load("SiteMap.xml");
  35. var items = LoadData(root);
  36.  
  37. // 构造数据源
  38. CollectionViewSource source = new CollectionViewSource();
  39. source.IsSourceGrouped = true;
  40. source.Source = items;
  41. source.ItemsPath = new PropertyPath("Items");
  42.  
  43. return source;
  44. }
  45. }
  46.  
  47. public SemanticZoomDemo()
  48. {
  49. this.InitializeComponent();
  50. }
  51.  
  52. private void btnToggleActiveView_Click(object sender, RoutedEventArgs e)
  53. {
  54. semanticZoom.ToggleActiveView();
  55. }
  56.  
  57. // 解析 xml 数据
  58. private List<NavigationModel> LoadData(XElement root)
  59. {
  60. if (root == null)
  61. return null;
  62.  
  63. var items = from n in root.Elements("node")
  64. select new NavigationModel
  65. {
  66. Title = (string)n.Attribute("title"),
  67. Url = (string)n.Attribute("url"),
  68. Items = LoadData(n)
  69. };
  70.  
  71. return items.ToList();
  72. }
  73. }
  74. }

2、ISemanticZoomInformation 的示例
Controls/CollectionControl/SemanticZoomDemo/MyFlipView.cs

  1. /*
  2. * 开发一个实现了 ISemanticZoomInformation 接口的自定义 FlipView
  3. * 由于本例仅用于 SemanticZoom 中 ZoomedInView 的演示,所以并没有实现 ISemanticZoomInformation 的全部逻辑
  4. * 两个 ISemanticZoomInformation 对象之间交互的核心逻辑就是通过 SemanticZoomLocation source 获取数据,通过 SemanticZoomLocation destination 设置数据
  5. *
  6. *
  7. * ISemanticZoomInformation - 用于 SemanticZoom 的 ZoomedInView 和 ZoomedOutView(说明详见本例中的注释)
  8. * SemanticZoomLocation - 用于设置或获取 ISemanticZoomInformation 在 SemanticZoom 中的状态(说明详见本例中的注释)
  9. */
  10.  
  11. using Windows.UI.Xaml.Controls;
  12. using Windows10.Common;
  13.  
  14. namespace Windows10.Controls.CollectionControl.SemanticZoomDemo
  15. {
  16. public class MyFlipView : FlipView, ISemanticZoomInformation
  17. {
  18. public MyFlipView()
  19. : base()
  20. {
  21.  
  22. }
  23.  
  24. /// <summary>
  25. /// 视图完成了变化后调用,比如视图完成了显示或隐藏之后都会调用这个(与 InitializeViewChange() 是一对)
  26. /// </summary>
  27. public void CompleteViewChange() { }
  28.  
  29. /// <summary>
  30. /// 完成 ZoomedInView -> ZoomedOutView 的切换时调用(与 StartViewChangeFrom() 是一对)
  31. /// </summary>
  32. public void CompleteViewChangeFrom(SemanticZoomLocation source, SemanticZoomLocation destination) { }
  33.  
  34. /// <summary>
  35. /// 完成 ZoomedOutView -> ZoomedInView 的切换时调用(与 StartViewChangeTo() 是一对)
  36. /// </summary>
  37. public void CompleteViewChangeTo(SemanticZoomLocation source, SemanticZoomLocation destination) { }
  38.  
  39. /// <summary>
  40. /// 视图将要发生变化时调用,比如视图将要被显示或将要被隐藏之前都会先调用这个(与 CompleteViewChange() 是一对)
  41. /// </summary>
  42. public void InitializeViewChange() { }
  43.  
  44. /// <summary>
  45. /// 是否为活动视图
  46. /// </summary>
  47. public bool IsActiveView { get; set; }
  48.  
  49. /// <summary>
  50. /// 是否为 ZoomedInView 视图
  51. /// </summary>
  52. public bool IsZoomedInView { get; set; }
  53.  
  54. /// <summary>
  55. /// 所属的 SemanticZoom
  56. /// </summary>
  57. public SemanticZoom SemanticZoomOwner { get; set; }
  58.  
  59. /// <summary>
  60. /// 开始 ZoomedInView -> ZoomedOutView 的切换时调用(与 CompleteViewChangeFrom() 是一对)
  61. /// </summary>
  62. public void StartViewChangeFrom(SemanticZoomLocation source, SemanticZoomLocation destination) { }
  63.  
  64. /// <summary>
  65. /// 开始 ZoomedOutView -> ZoomedInView 的切换时调用(与 CompleteViewChangeTo() 是一对)
  66. /// </summary>
  67. /// <param name="source">在 ZoomedOutView 时被选中的数据</param>
  68. /// <param name="destination">需要传递给 ZoomedInView 的数据</param>
  69. public void StartViewChangeTo(SemanticZoomLocation source, SemanticZoomLocation destination)
  70. {
  71. /*
  72. * 注:
  73. * 1、ListViewBase 实现了 ISemanticZoomInformation 接口,其通过绑定 CollectionViewSource 数据即可使 SemanticZoom 中的两个视图进行有关联地切换,参见 /Controls/CollectionControl/SemanticZoomDemo/SemanticZoomDemo.xaml
  74. * 2、对于 ListViewBase 来说,它运行到这里时,通过 source.Item 获取到的是一个 ICollectionViewGroup 类型的数据,其有两个属性:Group 和 GroupItems
  75. */
  76.  
  77. // 获取在 ZoomedOutView 中被选中的项,即被选中的父亲
  78. NavigationModel model = source.Item as NavigationModel;
  79.  
  80. // 将此父亲的所有子数据传递给 ZoomedInView,接下来会执行 MakeVisible() 方法
  81. destination.Item = model.Items;
  82. }
  83.  
  84. /// <summary>
  85. /// 开始 ZoomedOutView -> ZoomedInView 之后,会调用此方法
  86. /// 一般在此处重整 ZoomedInView 的数据源,或者滚动 ZoomedInView 中的内容到指定的项以对应 ZoomedOutView 中被选中的数据
  87. /// </summary>
  88. /// <param name="item">由 StartViewChangeTo() 方法传递给 ZoomedInView 的数据</param>
  89. public void MakeVisible(SemanticZoomLocation item)
  90. {
  91. // 将 FlipView 的数据源指定为被选中的父亲的所有子数据
  92. this.ItemsSource = item.Item;
  93. }
  94. }
  95. }

Controls/CollectionControl/SemanticZoomDemo/ISemanticZoomInformationDemo.xaml

  1. <Page
  2. x:Class="Windows10.Controls.CollectionControl.SemanticZoomDemo.ISemanticZoomInformationDemo"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:Windows10.Controls.CollectionControl.SemanticZoomDemo"
  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.  
  10. <Grid Background="Transparent">
  11.  
  12. <Button Name="btnDisplayZoomedOutView" Content="切换至 ZoomedInView 视图" Click="btnDisplayZoomedOutView_Click" VerticalAlignment="Top" Margin="10 0 10 10" />
  13.  
  14. <SemanticZoom x:Name="semanticZoom" IsZoomedInViewActive="False" Margin="10 50 10 10">
  15.  
  16. <SemanticZoom.ZoomedInView>
  17. <local:MyFlipView Name="flipView" Width="600" Height="300" HorizontalAlignment="Left" VerticalAlignment="Top">
  18. <FlipView.ItemTemplate>
  19. <DataTemplate>
  20. <TextBlock Text="{Binding Title}" FontSize="32" />
  21. </DataTemplate>
  22. </FlipView.ItemTemplate>
  23. <FlipView.ItemContainerStyle>
  24. <Style TargetType="FlipViewItem">
  25. <Setter Property="Background" Value="Blue" />
  26. </Style>
  27. </FlipView.ItemContainerStyle>
  28. </local:MyFlipView>
  29. </SemanticZoom.ZoomedInView>
  30.  
  31. <SemanticZoom.ZoomedOutView>
  32. <GridView Name="gridView">
  33. <GridView.ItemTemplate>
  34. <DataTemplate>
  35. <Grid Background="Orange" Width="100" Height="100">
  36. <TextBlock TextWrapping="Wrap" Text="{Binding Title}" />
  37. </Grid>
  38. </DataTemplate>
  39. </GridView.ItemTemplate>
  40. </GridView>
  41. </SemanticZoom.ZoomedOutView>
  42.  
  43. </SemanticZoom>
  44.  
  45. </Grid>
  46. </Page>

Controls/CollectionControl/SemanticZoomDemo/ISemanticZoomInformationDemo.xaml.cs

  1. /*
  2. * 演示 SemanticZoom 如何与自定义的 ISemanticZoomInformation 类结合使用(本例开发了一个实现了 ISemanticZoomInformation 接口的自定义 FlipView,参见 MyFlipView.cs)
  3. * ZoomedInView 用自定义的 FlipView 演示,ZoomedOutView 用 GridView 演示
  4. *
  5. *
  6. * 注:
  7. * ListViewBase 实现了 ISemanticZoomInformation 接口,所以可以在 SemanticZoom 的两个视图间有关联地切换。如果想让其它控件也实现类似的功能,就必须使其实现 ISemanticZoomInformation 接口
  8. */
  9.  
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Xml.Linq;
  13. using Windows.UI.Xaml.Controls;
  14. using Windows10.Common;
  15.  
  16. namespace Windows10.Controls.CollectionControl.SemanticZoomDemo
  17. {
  18. public sealed partial class ISemanticZoomInformationDemo : Page
  19. {
  20. public ISemanticZoomInformationDemo()
  21. {
  22. this.InitializeComponent();
  23. XElement root = XElement.Load("SiteMap.xml");
  24. var items = LoadData(root);
  25.  
  26. // 绑定数据
  27. gridView.ItemsSource = items;
  28. }
  29.  
  30. // 获取数据
  31. private List<NavigationModel> LoadData(XElement root)
  32. {
  33. if (root == null)
  34. return null;
  35.  
  36. var items = from n in root.Elements("node")
  37. select new NavigationModel
  38. {
  39. Title = (string)n.Attribute("title"),
  40. Url = (string)n.Attribute("url"),
  41. Items = LoadData(n)
  42. };
  43.  
  44. return items.ToList();
  45. }
  46.  
  47. private void btnDisplayZoomedOutView_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
  48. {
  49. semanticZoom.IsZoomedInViewActive = false;
  50. }
  51. }
  52. }

OK
[源码下载]

背水一战 Windows 10 (55) - 控件(集合类): SemanticZoom, ISemanticZoomInformation的更多相关文章

  1. 背水一战 Windows 10 (49) - 控件(集合类): Pivot, Hub

    [源码下载] 背水一战 Windows 10 (49) - 控件(集合类): Pivot, Hub 作者:webabcd 介绍背水一战 Windows 10 之 控件(集合类) Pivot Hub 示 ...

  2. 背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项

    [源码下载] 背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项 作者:webabcd 介绍背水一战 Windows 10 之 控件(集合 ...

  3. 背水一战 Windows 10 (48) - 控件(集合类): FlipView

    [源码下载] 背水一战 Windows 10 (48) - 控件(集合类): FlipView 作者:webabcd 介绍背水一战 Windows 10 之 控件(集合类) FlipView 示例Fl ...

  4. 背水一战 Windows 10 (50) - 控件(集合类): ItemsControl - 基础知识, 数据绑定, ItemsPresenter, GridViewItemPresenter, ListViewItemPresenter

    [源码下载] 背水一战 Windows 10 (50) - 控件(集合类): ItemsControl - 基础知识, 数据绑定, ItemsPresenter, GridViewItemPresen ...

  5. 背水一战 Windows 10 (51) - 控件(集合类): ItemsControl - 项模板选择器, 数据分组

    [源码下载] 背水一战 Windows 10 (51) - 控件(集合类): ItemsControl - 项模板选择器, 数据分组 作者:webabcd 介绍背水一战 Windows 10 之 控件 ...

  6. 背水一战 Windows 10 (52) - 控件(集合类): ItemsControl - 自定义 ItemsControl, 自定义 ContentPresenter

    [源码下载] 背水一战 Windows 10 (52) - 控件(集合类): ItemsControl - 自定义 ItemsControl, 自定义 ContentPresenter 作者:weba ...

  7. 背水一战 Windows 10 (53) - 控件(集合类): ItemsControl 的布局控件 - ItemsStackPanel, ItemsWrapGrid

    [源码下载] 背水一战 Windows 10 (53) - 控件(集合类): ItemsControl 的布局控件 - ItemsStackPanel, ItemsWrapGrid 作者:webabc ...

  8. 背水一战 Windows 10 (54) - 控件(集合类): ItemsControl 的布局控件 - OrientedVirtualizingPanel, VirtualizingStackPanel, WrapGrid

    [源码下载] 背水一战 Windows 10 (54) - 控件(集合类): ItemsControl 的布局控件 - OrientedVirtualizingPanel, VirtualizingS ...

  9. 背水一战 Windows 10 (57) - 控件(集合类): ListViewBase - 增量加载, 分步绘制

    [源码下载] 背水一战 Windows 10 (57) - 控件(集合类): ListViewBase - 增量加载, 分步绘制 作者:webabcd 介绍背水一战 Windows 10 之 控件(集 ...

随机推荐

  1. Netsharp下微信菜单以及OAuth

    一.OAuth介绍 在微信开发中,当打开一个页面是,业务场景一般会基于粉丝绑定用户信息,即页面需要基于粉丝和用户的身份处理业务逻辑. 在微信中打开一个页面有三个场景: 1.文本回复中直接包含url 2 ...

  2. js值类型与引用类型

    JavaScript值类型和引用类型有哪些 (1)值类型:数值.布尔值.null.undefined. (2)引用类型:对象.数组.函数. 三.如何理解值类型和引用类型及举例 我们可以用“连锁店”和“ ...

  3. VMware 15 Pro密钥

    YG5H2-ANZ0H-M8ERY-TXZZZ-YKRV8 UG5J2-0ME12-M89WY-NPWXX-WQH88 UA5DR-2ZD4H-089FY-6YQ5T-YPRX6 GA590-86Y0 ...

  4. 155. Min Stack - Unsolved

    https://leetcode.com/problems/min-stack/#/solutions Design a stack that supports push, pop, top, and ...

  5. bootstrap之css样式

    一 bootstrap的介绍 Bootstrap是将html,css和js的代码打包好了,只管我们拿来调用.是基于jquery开发的. 使用BootCDN提供的免费CDN加速服务,同时支持http和h ...

  6. sqlserver 修改数据库表所有者

    SQLServer修改表所有者  来自:http://www.cnblogs.com/tearer/archive/2012/09/16/2687802.html 批量修改:EXEC sp_MSfor ...

  7. 5. Sports 体育运动

    5. Sports 体育运动 (1) Sport is not only physically challenging,but it can also be mentally challenging. ...

  8. Eclipse错误: 找不到或无法加载主类或项目无法编译10种解决大法

    1.在src文件夹上点右键-Build Path-Use as Source Folder,重新进行编译,一切正常了.2.在Eclipse工程文件夹上点右键-Refresh,重新编译,一功OK(这个方 ...

  9. load data会被当成一个事务处理ERROR 1197

    问题现象: l有一份csv格式的文件,大小在14G左右.max_binlog_cache_size=4G. 登录mysql实例,选择对应的表通过load data往指定表里导数.大概20分钟左右,报以 ...

  10. Failed to place enough replicas

    如果DataNode的dfs.datanode.data.dir全配置成SSD类型,则执行"hdfs dfs -put /etc/hosts hdfs:///tmp/"时会报如下错 ...