设为首页 收藏本站
查看: 696|回复: 0

[经验分享] 背水一战 Windows 10 (49)

[复制链接]

尚未签到

发表于 2017-6-28 12:27:59 | 显示全部楼层 |阅读模式
  [源码下载]




背水一战 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[0] 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 > 0)
{
lblMsg.Text += "hub_SectionsInViewChanged RemovedSections: " + e.RemovedSections[0].Header.ToString();
lblMsg.Text += Environment.NewLine;
}
// 此次在 hub 中移入的 HubSection
if (e.AddedSections.Count > 0)
{
lblMsg.Text += "hub_SectionsInViewChanged AddedSections: " + e.AddedSections[0].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
[源码下载]

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-388980-1-1.html 上篇帖子: 使用vlmcsd自建KMS服务~一句命令激活windows/office 下篇帖子: React Native环境配置之Windows版本搭建
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表