背水一战 Windows 10 (55) - 控件(集合类): SemanticZoom, ISemanticZoomInformation
生活随笔
收集整理的這篇文章主要介紹了
背水一战 Windows 10 (55) - 控件(集合类): SemanticZoom, ISemanticZoomInformation
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
原文:背水一戰(zhàn) Windows 10 (55) - 控件(集合類): SemanticZoom, ISemanticZoomInformation
[源碼下載]
作者:webabcd
介紹
背水一戰(zhàn) Windows 10 之 控件(集合類)
- SemanticZoom
- ISemanticZoomInformation
示例
1、SemanticZoom 的示例
Controls/CollectionControl/SemanticZoomDemo/SemanticZoomDemo.xaml
Controls/CollectionControl/SemanticZoomDemo/SemanticZoomDemo.xaml.cs
/** SemanticZoom - SemanticZoom 控件(繼承自 Control, 請(qǐng)參見 /Controls/BaseControl/ControlDemo/)* ToggleActiveView() - 在 ZoomedInView, ZoomedOutView 兩個(gè)視圖之間切換* ViewChangeStarted - 視圖切換開始時(shí)觸發(fā)的事件 * ViewChangeCompleted - 視圖切換完成時(shí)觸發(fā)的事件* * * CollectionViewSource - 對(duì)集合數(shù)據(jù)啟用分組支持* Source - 數(shù)據(jù)源* View - 獲取視圖對(duì)象,返回一個(gè)實(shí)現(xiàn)了 ICollectionView 接口的對(duì)象* IsSourceGrouped - 數(shù)據(jù)源是否是一個(gè)被分組的數(shù)據(jù)* ItemsPath - 數(shù)據(jù)源中,子數(shù)據(jù)集合的屬性名稱* * ICollectionView - 支持?jǐn)?shù)據(jù)分組是 ICollectionView 的作用之一* CollectionGroups - 組數(shù)據(jù)集合*/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);// 構(gòu)造數(shù)據(jù)源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 數(shù)據(jù)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 類結(jié)合使用(本例開發(fā)了一個(gè)實(shí)現(xiàn)了 ISemanticZoomInformation 接口的自定義 FlipView,參見 MyFlipView.cs)* ZoomedInView 用自定義的 FlipView 演示,ZoomedOutView 用 GridView 演示* * * 注:* ListViewBase 實(shí)現(xiàn)了 ISemanticZoomInformation 接口,所以可以在 SemanticZoom 的兩個(gè)視圖間有關(guān)聯(lián)地切換。如果想讓其它控件也實(shí)現(xiàn)類似的功能,就必須使其實(shí)現(xiàn) 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);// 綁定數(shù)據(jù)gridView.ItemsSource = items;}// 獲取數(shù)據(jù)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
[源碼下載]
總結(jié)
以上是生活随笔為你收集整理的背水一战 Windows 10 (55) - 控件(集合类): SemanticZoom, ISemanticZoomInformation的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML script 标签
- 下一篇: 【全栈React】第13天: 重复元素