[源码下载]

重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar

作者:webabcd

介绍
重新想象 Windows 8.1 Store Apps 之新增控件

  • AppBar - 应用程序栏控件(新增了 AppBarButton, AppBarToggleButton, AppBarSeparator)
  • CommandBar - 应用程序栏控件(AppBar 简化版)

示例
1、演示 AppBar 的应用
AppBarDemo.xaml

<Page
x:Class="Windows81.Controls.AppBarDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Controls"
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="120 0 0 0"> <CheckBox Name="chkIsCompact" Content="IsCompact" IsChecked="False" Checked="chkIsCompact_Checked" Unchecked="chkIsCompact_Unchecked" /> <Button Name="btnOpen" Content="打开 AppBar" Click="btnOpen_Click" Margin="0 10 0 0" />
<Button Name="btnClose" Content="关闭 AppBar" Click="btnClose_Click" Margin="0 10 0 0" /> </StackPanel>
</Grid> <!--
AppBar 的 win8 时代的用法参见:http://www.cnblogs.com/webabcd/archive/2013/01/14/2859153.html
其用法很怪异,到了 win8.1 时代终于正常了,以下会介绍 AppBar 在 win8.1 时代的用法 在 win8.1 时代我们需要指定 AppBar 的按钮的图标和文本,系统会自动在图标外面加个圈圈
-->
<Page.BottomAppBar>
<AppBar x:Name="appBar" IsSticky="True" Padding="10,0">
<StackPanel Name="buttonPanel" Orientation="Horizontal" HorizontalAlignment="Left"> <!--
AppBarButton - AppBar 中的 Button
Icon - 按钮的图标(可以指定一个图片,也可以指定一个 Symbol enumeration)
Label - 按钮的文本
--> <!--
Icon 来自 Symbol enumeration,参见本文件夹中的 Symbol enumeration (Windows).mht 文件
-->
<AppBarButton Icon="Play" Label="SymbolIcon" /> <!--
Icon 来自一个图片
-->
<AppBarButton Label="BitmapIcon" >
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/Logo.png"/>
</AppBarButton.Icon>
</AppBarButton> <!--
AppBarSeparator - AppBar 中的 分隔符
-->
<AppBarSeparator /> <!--
AppBarToggleButton - AppBar 中的 ToggleButton
Icon - 按钮的图标(可以指定为一个 FontIcon 或 PathIcon)
Label - 按钮的文本
--> <!--
Icon 来自 FontIcon
-->
<AppBarToggleButton Label="FontIcon" >
<AppBarToggleButton.Icon>
<FontIcon FontFamily="Candara" Glyph="Σ"/>
</AppBarToggleButton.Icon>
</AppBarToggleButton> <!--
Icon 来自 PathIcon
-->
<AppBarToggleButton Label="PathIcon" >
<AppBarToggleButton.Icon>
<PathIcon Data="F1 M 20,20L 24,10L 24,24L 5,24"/>
</AppBarToggleButton.Icon>
</AppBarToggleButton> <!--
AppBarButton, AppBarToggleButton, AppBarSeparator 有一个属性:IsCompact - 是否使用紧凑按钮,即是否隐藏按钮文本(true - 只显示按钮图标;false - 显示按钮图标和按钮文本)
--> </StackPanel>
</AppBar>
</Page.BottomAppBar>
</Page>

AppBarDemo.xaml.cs

/*
* AppBar - 应用程序栏控件
* win8.1 的 AppBar 相对于 win8 有了增强,即增加了对 AppBarButton, AppBarToggleButton, AppBarSeparator 的支持
*
* 本例主要介绍 win8.1 中的 AppBar 改进的地方,原有 AppBar 的知识点参见:http://www.cnblogs.com/webabcd/archive/2013/01/14/2859153.html
*
* 注:
* 1、当应用程序栏只有 AppBarButton, AppBarToggleButton, AppBarSeparator 的时候建议使用 CommandBar
* 2、如果除了 AppBarButton, AppBarToggleButton, AppBarSeparator 之外,应用程序栏还需要其他元素,则需要使用 AppBar
*/ using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows81.Controls
{
public sealed partial class AppBarDemo : Page
{
public AppBarDemo()
{
this.InitializeComponent();
} private void btnOpen_Click(object sender, RoutedEventArgs e)
{
// 打开 AppBar
appBar.IsOpen = true;
} private void btnClose_Click(object sender, RoutedEventArgs e)
{
// 关闭 AppBar
appBar.IsOpen = false;
} private void chkIsCompact_Checked(object sender, RoutedEventArgs e)
{
var elements = buttonPanel.Children;
foreach (var element in elements)
{
var button = element as ICommandBarElement;
if (button != null)
{
// IsCompact - 是否使用紧凑按钮,即是否隐藏按钮文本(来自 ICommandBarElement 接口。AppBarButton, AppBarToggleButton, AppBarSeparator 均实现了此接口)
// true - 只显示按钮图标(如果是 AppBarSeparator 的话会相对短一点)
// false - 显示按钮图标和按钮文本(如果是 AppBarSeparator 的话会相对长一点)
button.IsCompact = true;
}
}
} private void chkIsCompact_Unchecked(object sender, RoutedEventArgs e)
{
var elements = buttonPanel.Children;
foreach (var element in elements)
{
var button = element as ICommandBarElement;
if (button != null)
{
button.IsCompact = false;
}
}
}
}
}

2、演示 CommandBar 的应用
CommandBarDemo.xaml

<Page
x:Class="Windows81.Controls.CommandBarDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Controls"
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="120 0 0 0"> <Button Name="btnOpen" Content="打开 CommandBar" Click="btnOpen_Click" Margin="0 10 0 0" />
<Button Name="btnClose" Content="关闭 CommandBar" Click="btnClose_Click" Margin="0 10 0 0" /> </StackPanel>
</Grid> <!--
CommandBar 是 win8.1 新增的应用程序栏控件
其内只能包含 AppBarButton, AppBarToggleButton, AppBarSeparator,详细用法参见 AppBarDemo.xaml AppBarButton, AppBarToggleButton, AppBarSeparator 有一个属性:IsCompact - 是否使用紧凑按钮,即是否隐藏按钮文本(true - 只显示按钮图标;false - 显示按钮图标和按钮文本)
注:无法手动设置 CommandBar 中的 AppBarButton, AppBarToggleButton, AppBarSeparator 的 IsCompact 属性,系统会根据当前窗口的大小自动设置此属性
-->
<Page.BottomAppBar>
<CommandBar x:Name="commandBar" IsSticky="True" Padding="10,0">
<AppBarToggleButton Icon="Shuffle" Label="Shuffle" />
<AppBarToggleButton Icon="RepeatAll" Label="Repeat" />
<AppBarSeparator/>
<AppBarButton Icon="Back" Label="Back" />
<AppBarButton Icon="Stop" Label="Stop" />
<AppBarButton Icon="Play" Label="Play" />
<AppBarButton Icon="Forward" Label="Forward" /> <!--
CommandBar.PrimaryCommands - 其内的按钮会显示在 CommandBar 的右侧
CommandBar.SecondaryCommands - 其内的按钮会显示在 CommandBar 的左侧 注:上面直接写在 CommandBar 中的按钮会自动添加进 CommandBar.PrimaryCommands
-->
<CommandBar.SecondaryCommands>
<AppBarButton Icon="Like" Label="Like" IsCompact="True" />
<AppBarButton Icon="Dislike" Label="Dislike" />
</CommandBar.SecondaryCommands>
</CommandBar>
</Page.BottomAppBar>
</Page>

CommandBarDemo.xaml.cs

/*
* CommandBar - 应用程序栏控件(AppBar 简化版)
*
* 注:
* 1、当应用程序栏只有 AppBarButton, AppBarToggleButton, AppBarSeparator 的时候建议使用 CommandBar
* 2、如果除了 AppBarButton, AppBarToggleButton, AppBarSeparator 之外,应用程序栏还需要其他元素,则需要使用 AppBar
*/ using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows81.Controls
{
public sealed partial class CommandBarDemo : Page
{
public CommandBarDemo()
{
this.InitializeComponent();
} private void btnOpen_Click(object sender, RoutedEventArgs e)
{
// 打开 CommandBar
commandBar.IsOpen = true;
} private void btnClose_Click(object sender, RoutedEventArgs e)
{
// 关闭 CommandBar
commandBar.IsOpen = false;
}
}
}

OK
[源码下载]

重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar的更多相关文章

  1. 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker

    [源码下载] 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker 作者:webabcd 介绍重新想象 Windows 8.1 ...

  2. 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout

    [源码下载] 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout 作者:webabcd 介绍重新想象 ...

  3. 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink

    [源码下载] 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink 作者:webabcd 介绍重新想象 Windows 8.1 Store A ...

  4. 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox

    [源码下载] 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox 作者:webabcd 介绍重新想象 Windows 8.1 Store Apps 之 ...

  5. 重新想象 Windows 8.1 Store Apps 系列文章索引

    [源码下载] [重新想象 Windows 8 Store Apps 系列文章] 重新想象 Windows 8.1 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...

  6. 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Contract 分享 WebView 中的内容, 为 WebView 截图

    [源码下载] 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Co ...

  7. 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性

    [源码下载] 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件 ...

  8. 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup

    [源码下载] 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup 作者:webabcd 介绍重新想象 Wind ...

  9. 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame

    [源码下载] 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame 作者:webabcd 介绍重新想象 Windows 8.1 St ...

随机推荐

  1. Discuz!开发手册

    如何使用Discuz开发手册? 1.首先建议你了解Discuz目录结构-全局篇 通过对目录结构的了解,会在以后的创作道路上提供坚实的基础! 2.你还需要了解Discuz! X3.1数据字典 3.创建自 ...

  2. 封装一个UILabel圆形边框显示进度

    封装了一个UILabel并让它显示圆形的边框,UILabel上面显示百份比,而边框则用Animation绘制到整个圆占指定百分比的点. 这只是我个人想的继承一个UILabel实现的,用到两个CASha ...

  3. 即将放出ITSEC第一期所有培训视频

    课程大概被分为三个章节 客户端安全培训 安全工具培训 服务端安全培训   部分PPT                         详细课程表 FireBug代码调试工具使用:工具介绍 FireBu ...

  4. 为Ubuntu笔记本电脑设置WiFi热点共享上网

    该文由土木坛子转译而来,说是转译,其实看截图就可以方便的设置,没有任何命令,全是图形界面,方便容易.我们都知道怎样在 windows 7 系统上如何设计 Wifi 热点,当你只有一条网线,多台计算机的 ...

  5. POJ 1186 方程的解数

    方程的解数 Time Limit: 15000MS   Memory Limit: 128000K Total Submissions: 6188   Accepted: 2127 Case Time ...

  6. 解决clone问题之外的体会

    adlnkoh.sh started at Thu Aug 25 15:42:51 CST 2016 Log file located at /u02/db/testdb/11.1.0/appsuti ...

  7. Redis内存数据库在Exchange会议室的应用

    本文论述了现有Exchange会议室应用现状和不足之处,并详细介绍了Redis内存数据库在Exchange会议室的应用,并给出了一种高性能的应用架构及采用关键技术和关键实现过程,最终实现大幅改进系统性 ...

  8. 基于jquery的响应式提示框SweetAlert

    介绍款交互性非常不错的jquery弹出层插件,支持消息提示.错误提示.确认框提示等.交互式体验感非常不错,比如咱们现在体验非常不错的微信支付.支付宝等完成后的效果.不过本插件至少支持IE9+.使用方式 ...

  9. Outlook Web App简介

    一.什么是Outlook Web AppOutlook Web Access简称OWA是基于微软Hosted Exchange技术的托管邮局的一项Web访问功能.通过访问Outlook Web Acc ...

  10. github神器--Atom编辑器初体验

    Atom 1.0正式式版已经出来好几天,自从听说github出了这神器之后,一直想体验一吧,这两天终于体验上. 下载: https://atom.io/ 其实,我的网速还不错,但总是下载到一半就没网速 ...