[源码下载]

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

作者:webabcd

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

  • Pivot
  • Hub

示例
1、Pivot 的示例
Controls/CollectionControl/PivotDemo.xaml

<Page
x:Class="Windows10.Controls.CollectionControl.PivotDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.CollectionControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <!--
Pivot - Pivot 控件
Title, TitleTemplate - 标题
LeftHeader, LeftHeaderTemplate - 左侧 header
RightHeader, RightHeaderTemplate - 右侧 header
HeaderTemplate - PivotItem 的 Header 的 DataTemplate
SelectionChanged - 选中的 item 发生变化时触发的事件
PivotItemUnloading - Pivot 内的某个 PivotItem 准备变成选中项时触发的事件
PivotItemLoaded - Pivot 内的某个 PivotItem 已经变成选中项时触发的事件
PivotItemUnloading - Pivot 内的某个 PivotItem 准备从选中项变为非选中项时触发的事件
PivotItemUnloaded - Pivot 内的某个 PivotItem 已经从选中项变为非选中项时触发的事件 PivotItem - PivotItem 控件
Header - 用于指定 PivotItem 的 Header,需要通过 Pivot.HeaderTemplate 来设置其 DataTemplate
--> <Pivot Name="pivot" Title="pivot title" Margin="5"
SelectionChanged="pivot_SelectionChanged"
PivotItemLoading="pivot_PivotItemLoading" PivotItemLoaded="pivot_PivotItemLoaded" PivotItemUnloading="pivot_PivotItemUnloading" PivotItemUnloaded="pivot_PivotItemUnloaded">
<Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="Red" />
</DataTemplate>
</Pivot.HeaderTemplate>
<Pivot.LeftHeader>
<TextBlock Text="left header" />
</Pivot.LeftHeader>
<Pivot.RightHeader>
<TextBlock Text="right header" />
</Pivot.RightHeader> <PivotItem Header="pivot item header 1">
<TextBlock Text="pivot item content 1" />
</PivotItem>
<PivotItem Header="pivot item header 2">
<TextBlock Text="pivot item content 2" />
</PivotItem>
<PivotItem Header="pivot item header 3">
<TextBlock Text="pivot item content 3" />
</PivotItem>
</Pivot> <Button Name="btnLock" Content="对 pivot 锁定或解除锁定" Margin="5" Click="btnLock_Click" /> <StackPanel Orientation="Horizontal">
<TextBlock Name="lblMsg1" Margin="5" />
<TextBlock Name="lblMsg2" Margin="5" />
</StackPanel> </StackPanel>
</Grid>
</Page>

Controls/CollectionControl/PivotDemo.xaml.cs

/*
* Pivot - Pivot 控件(继承自 ItemsControl, 请参见 /Controls/CollectionControl/ItemsControlDemo/)
* IsLocked - 是否锁定 Pivot,锁定后只会显示当前选中的 item,而不能切换
* SelectedItem - 当前选中的 item
* SelectedIndex - 当前选中的 item 的索引位置
*
* PivotItem - PivotItem 控件(继承自 ContentControl, 请参见 /Controls/BaseControl/ContentControlDemo/)
*/ using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows10.Controls.CollectionControl
{
public sealed partial class PivotDemo : Page
{
public PivotDemo()
{
this.InitializeComponent();
} private void btnLock_Click(object sender, RoutedEventArgs e)
{
pivot.IsLocked ^= true;
} private void pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// e.RemovedItems - 本次事件中,被取消选中的项
// e.AddedItems - 本次事件中,新被选中的项 lblMsg1.Text = "SelectionChangedEventArgs.AddedItems: " + (e.AddedItems[] as PivotItem).Header.ToString();
lblMsg1.Text += Environment.NewLine;
lblMsg1.Text += "Pivot.SelectedIndex: " + pivot.SelectedIndex;
lblMsg1.Text += Environment.NewLine;
lblMsg1.Text += "Pivot.SelectedItem: " + (pivot.SelectedItem as PivotItem).Header.ToString();
} // 某 PivotItem 准备变成选中项
private void pivot_PivotItemLoading(Pivot sender, PivotItemEventArgs args)
{
// args.Item - 相关的 PivotItem 对象 lblMsg2.Text += "pivot_PivotItemLoading: " + args.Item.Header.ToString();
lblMsg2.Text += Environment.NewLine;
} // 某 PivotItem 已经变成选中项
private void pivot_PivotItemLoaded(Pivot sender, PivotItemEventArgs args)
{
lblMsg2.Text += "pivot_PivotItemLoaded: " + args.Item.Header.ToString();
lblMsg2.Text += Environment.NewLine;
} // 某 PivotItem 准备从选中项变为非选中项
private void pivot_PivotItemUnloading(Pivot sender, PivotItemEventArgs args)
{
lblMsg2.Text += "pivot_PivotItemUnloading: " + args.Item.Header.ToString();
lblMsg2.Text += Environment.NewLine;
} // 某 PivotItem 已经从选中项变为非选中项
private void pivot_PivotItemUnloaded(Pivot sender, PivotItemEventArgs args)
{
lblMsg2.Text += "pivot_PivotItemUnloaded: " + args.Item.Header.ToString();
lblMsg2.Text += Environment.NewLine;
}
}
}

2、Hub 的示例
Controls/CollectionControl/HubDemo.xaml

<Page
x:Class="Windows10.Controls.CollectionControl.HubDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.CollectionControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent"> <TextBlock Name="lblMsg" Margin="10 0 10 10" Width="200" TextWrapping="Wrap" HorizontalAlignment="Left" /> <SemanticZoom Margin="210 0 10 10">
<SemanticZoom.ZoomedInView> <!--
Hub - Hub 控件
DefaultSectionIndex - hub 初始化时,被选中的 HubSection 的索引位置
Header, HeaderTemplate - hub 的 header
Orientation - hub 的子元素们的排列方式(Horizontal, Vertical)
Sections - hub 的 HubSection([ContentProperty(Name = "Sections")])
SectionHeaderClick - 点击 HubSection 右上角的“查看更多”按钮时触发的事件
SectionsInViewChanged - 可视区中的 HubSection 发生变化时触发的事件 HubSection - HubSection 控件
Header, HeaderTemplate - HubSection 的 header
ContentTemplate - HubSection 的控件模板([ContentProperty(Name = "ContentTemplate")])
IsHeaderInteractive - 是否显示 HubSection 右上角的“查看更多”按钮
--> <Hub Name="hub" Orientation="Horizontal" Header="hub title" DefaultSectionIndex="1" SectionHeaderClick="hub_SectionHeaderClick" SectionsInViewChanged="hub_SectionsInViewChanged">
<HubSection Background="Orange" IsHeaderInteractive="False" Header="hub section header 1">
<DataTemplate>
<TextBlock Text="hub section content 1" />
</DataTemplate>
</HubSection>
<HubSection Background="Orange" IsHeaderInteractive="False" Header="hub section header 2">
<DataTemplate>
<TextBlock Text="hub section content 2" />
</DataTemplate>
</HubSection>
<HubSection Background="Orange" IsHeaderInteractive="False" Header="hub section header 3">
<DataTemplate>
<TextBlock Text="hub section content 3" />
</DataTemplate>
</HubSection>
<HubSection Background="Orange" IsHeaderInteractive="True" Header="hub section header 4">
<DataTemplate>
<TextBlock Text="hub section content 4" />
</DataTemplate>
</HubSection>
<HubSection Background="Orange" IsHeaderInteractive="True" Header="hub section header 5">
<DataTemplate>
<TextBlock Text="hub section content 5" />
</DataTemplate>
</HubSection>
<HubSection Background="Orange" IsHeaderInteractive="True" Header="hub section header 6">
<DataTemplate>
<TextBlock Text="hub section content 6" />
</DataTemplate>
</HubSection>
</Hub>
</SemanticZoom.ZoomedInView> <SemanticZoom.ZoomedOutView>
<ListView x:Name="listView"/>
</SemanticZoom.ZoomedOutView>
</SemanticZoom> </Grid>
</Page>

Controls/CollectionControl/HubDemo.xaml.cs

/*
* Hub - Hub 控件(继承自 Control, 请参见 /Controls/BaseControl/ControlDemo/)
* SectionsInView - 用于获取当前可视区中显示的全部 HubSection 集合
* SectionHeaders - 用于获取当前可视区中显示的全部 HubSection 对象的 Header 集合
*
* HubSection - HubSection 控件(继承自 Control, 请参见 /Controls/BaseControl/ControlDemo/)
*
*
* 注:
* Hub 实现了 ISemanticZoomInformation 接口,所以可以在 SemanticZoom 的两个视图间有关联地切换。关于 ISemanticZoomInformation 请参见 /Controls/CollectionControl/SemanticZoomDemo/ISemanticZoomInformationDemo.xaml
*/ using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows10.Controls.CollectionControl
{
public sealed partial class HubDemo : Page
{
public HubDemo()
{
this.InitializeComponent(); this.Loaded += HubDemo_Loaded;
} private void HubDemo_Loaded(object sender, RoutedEventArgs e)
{
// 拿到所有 HubSection 的 header 集合
List<string> headers = new List<string>();
foreach (HubSection section in hub.Sections)
{
if (section.Header != null)
{ headers.Add(section.Header.ToString());
}
} listView.ItemsSource = headers;
} private void hub_SectionHeaderClick(object sender, HubSectionHeaderClickEventArgs e)
{
// 获取通过点击 HubSection 右上角的“查看更多”按钮而被选中的 HubSection 对象
lblMsg.Text = "hub_SectionHeaderClick: " + e.Section.Header.ToString();
} private void hub_SectionsInViewChanged(object sender, SectionsInViewChangedEventArgs e)
{
lblMsg.Text = ""; // 此次在 hub 中移出的 HubSection
if (e.RemovedSections.Count > )
{
lblMsg.Text += "hub_SectionsInViewChanged RemovedSections: " + e.RemovedSections[].Header.ToString();
lblMsg.Text += Environment.NewLine;
} // 此次在 hub 中移入的 HubSection
if (e.AddedSections.Count > )
{
lblMsg.Text += "hub_SectionsInViewChanged AddedSections: " + e.AddedSections[].Header.ToString();
lblMsg.Text += Environment.NewLine;
} lblMsg.Text += "hub.SectionsInView: ";
lblMsg.Text += Environment.NewLine;
// 可视区中显示的全部 HubSection
foreach (var item in hub.SectionsInView)
{
lblMsg.Text += item.Header.ToString();
lblMsg.Text += Environment.NewLine;
}
}
}
}

OK
[源码下载]

背水一战 Windows 10 (49) - 控件(集合类): Pivot, Hub的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

    [源码下载] 背水一战 Windows 10 (55) - 控件(集合类): SemanticZoom, ISemanticZoomInformation 作者:webabcd 介绍背水一战 Wind ...

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

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

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

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

随机推荐

  1. jvm 基础

    1. JDK 包含 java 程序设计语言,JVM, Java API类库. java 开发最小环境 2. JRE : Java API类库中java se API 子集和java 虚拟机(HotSp ...

  2. 使用SpringMVC的@CrossOrigin注解解决跨域请求问题

    跨域问题,通俗说就是用ajax请求其他站点的接口,浏览器默认是不允许的.同源策略(Same-orgin policy)限制了一个源(orgin)中加载脚本或脚本与来自其他源(orgin)中资源的交互方 ...

  3. 绝对强大的三个linux指令: ar, nm, objdump

    前言如果普通编程不需要了解这些东西,如果想精确控制你的对象文件的格式或者你想查看一下文件对象里的内容以便作出某种判断,刚你可以看一下下面的工具:objdump, nm, ar.当然,本文不可能非常详细 ...

  4. clion配置c/c++环境

    打开这个界面  点击添加Cygwin选择下载的Cygwin在进行下面的配置 去网站https://www.cygwin.com/选择路径即可(这里只写了配置过程中的关键步骤并且附上IDE的链接直接安装 ...

  5. 2018.12.30 poj3734 Blocks(生成函数)

    传送门 生成函数入门题. 按照题意构造函数: 对于限定必须是出现偶数次的颜色:1+x22!+x44!+...=ex+e−x21+\frac {x^2}{2!}+\frac {x^4}{4!}+...= ...

  6. 关于xftp上传文件状态错误的解决

    新建一个文件夹,/usr/local/wwj 更改wwj权限 chmod 777 wwj 然后就可以上传了 如果还不行,就关闭防火墙

  7. django调用py报错 django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured.

    完整报错信息如下 django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, bu ...

  8. php,合并数组,合并一维数组,合并二维数组,合并多维数组

    合并数组 例子1: <?php $msg = [ "code" => "0", "msg" => "" ...

  9. kettle之时间字段默认值为空或’0000-00-00’问题

    今天使用kettle从mysql导数到oracle,发现只导了7行后,数据传输就终止了,查看日志信息,报错如下: 报:Couldn't get row from result set问题. 发现从这行 ...

  10. TCP、UDP之三次握手四次挥手

    1. http协议的简介 HTTP,HyperText Transfer Protocol.超文本传输协议,是互联网上应用最为广泛的一种网络协议.基于TCP的协议,HTTP是一个客户端和服务器端请求和 ...