当前位置:
首页 >
背水一战 Windows 10 (55) - 控件(集合类): SemanticZoom, ISemanticZoomInformation
发布时间:2025/3/15
41
豆豆
生活随笔
收集整理的这篇文章主要介绍了
背水一战 Windows 10 (55) - 控件(集合类): SemanticZoom, ISemanticZoomInformation
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
原文:背水一战 Windows 10 (55) - 控件(集合类): SemanticZoom, ISemanticZoomInformation
[源码下载]
作者:webabcd
介绍
背水一战 Windows 10 之 控件(集合类)
- SemanticZoom
- ISemanticZoomInformation
示例
1、SemanticZoom 的示例
Controls/CollectionControl/SemanticZoomDemo/SemanticZoomDemo.xaml
Controls/CollectionControl/SemanticZoomDemo/SemanticZoomDemo.xaml.cs
/** SemanticZoom - SemanticZoom 控件(继承自 Control, 请参见 /Controls/BaseControl/ControlDemo/)* ToggleActiveView() - 在 ZoomedInView, ZoomedOutView 两个视图之间切换* ViewChangeStarted - 视图切换开始时触发的事件 * ViewChangeCompleted - 视图切换完成时触发的事件* * * CollectionViewSource - 对集合数据启用分组支持* Source - 数据源* View - 获取视图对象,返回一个实现了 ICollectionView 接口的对象* IsSourceGrouped - 数据源是否是一个被分组的数据* ItemsPath - 数据源中,子数据集合的属性名称* * ICollectionView - 支持数据分组是 ICollectionView 的作用之一* CollectionGroups - 组数据集合*/using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Data; using Windows10.Common;namespace Windows10.Controls.CollectionControl.SemanticZoomDemo {public sealed partial class SemanticZoomDemo : Page{public CollectionViewSource MyData{get{XElement root = XElement.Load("SiteMap.xml");var items = LoadData(root);// 构造数据源CollectionViewSource source = new CollectionViewSource();source.IsSourceGrouped = true;source.Source = items;source.ItemsPath = new PropertyPath("Items");return source;}}public SemanticZoomDemo(){this.InitializeComponent();}private void btnToggleActiveView_Click(object sender, RoutedEventArgs e){semanticZoom.ToggleActiveView();}// 解析 xml 数据private List<NavigationModel> LoadData(XElement root){if (root == null)return null;var items = from n in root.Elements("node")select new NavigationModel{Title = (string)n.Attribute("title"),Url = (string)n.Attribute("url"),Items = LoadData(n)};return items.ToList();}} }
2、ISemanticZoomInformation 的示例
Controls/CollectionControl/SemanticZoomDemo/MyFlipView.cs
Controls/CollectionControl/SemanticZoomDemo/ISemanticZoomInformationDemo.xaml
<Pagex:Class="Windows10.Controls.CollectionControl.SemanticZoomDemo.ISemanticZoomInformationDemo"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:Windows10.Controls.CollectionControl.SemanticZoomDemo"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"><Grid Background="Transparent"><Button Name="btnDisplayZoomedOutView" Content="切换至 ZoomedInView 视图" Click="btnDisplayZoomedOutView_Click" VerticalAlignment="Top" Margin="10 0 10 10" /><SemanticZoom x:Name="semanticZoom" IsZoomedInViewActive="False" Margin="10 50 10 10"><SemanticZoom.ZoomedInView><local:MyFlipView Name="flipView" Width="600" Height="300" HorizontalAlignment="Left" VerticalAlignment="Top"><FlipView.ItemTemplate><DataTemplate><TextBlock Text="{Binding Title}" FontSize="32" /></DataTemplate></FlipView.ItemTemplate><FlipView.ItemContainerStyle><Style TargetType="FlipViewItem"><Setter Property="Background" Value="Blue" /></Style></FlipView.ItemContainerStyle></local:MyFlipView></SemanticZoom.ZoomedInView><SemanticZoom.ZoomedOutView><GridView Name="gridView"><GridView.ItemTemplate><DataTemplate><Grid Background="Orange" Width="100" Height="100"><TextBlock TextWrapping="Wrap" Text="{Binding Title}" /></Grid></DataTemplate></GridView.ItemTemplate></GridView></SemanticZoom.ZoomedOutView></SemanticZoom></Grid> </Page>Controls/CollectionControl/SemanticZoomDemo/ISemanticZoomInformationDemo.xaml.cs
/** 演示 SemanticZoom 如何与自定义的 ISemanticZoomInformation 类结合使用(本例开发了一个实现了 ISemanticZoomInformation 接口的自定义 FlipView,参见 MyFlipView.cs)* ZoomedInView 用自定义的 FlipView 演示,ZoomedOutView 用 GridView 演示* * * 注:* ListViewBase 实现了 ISemanticZoomInformation 接口,所以可以在 SemanticZoom 的两个视图间有关联地切换。如果想让其它控件也实现类似的功能,就必须使其实现 ISemanticZoomInformation 接口*/using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using Windows.UI.Xaml.Controls; using Windows10.Common;namespace Windows10.Controls.CollectionControl.SemanticZoomDemo {public sealed partial class ISemanticZoomInformationDemo : Page{public ISemanticZoomInformationDemo(){this.InitializeComponent();XElement root = XElement.Load("SiteMap.xml");var items = LoadData(root);// 绑定数据gridView.ItemsSource = items;}// 获取数据private List<NavigationModel> LoadData(XElement root){if (root == null)return null;var items = from n in root.Elements("node")select new NavigationModel{Title = (string)n.Attribute("title"),Url = (string)n.Attribute("url"),Items = LoadData(n)};return items.ToList();}private void btnDisplayZoomedOutView_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e){semanticZoom.IsZoomedInViewActive = false;}} }
OK
[源码下载]
总结
以上是生活随笔为你收集整理的背水一战 Windows 10 (55) - 控件(集合类): SemanticZoom, ISemanticZoomInformation的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: HTML script 标签
- 下一篇: Windows 10三月更新补丁竟高达3