[源码下载]

重新想象 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. 如何闪开安装VS2013必须要有安装IE10的限制

    把下面这一段文字,储存成.bat档案,然后右击以管理员角色去执行它.@ECHO OFF :IE10HACK REG ADD "HKLM\SOFTWARE\Wow6432Node\Micros ...

  2. nlog(n)解动态规划--最长上升子序列(Longest increasing subsequence)

    最长上升子序列LIS问题属于动态规划的初级问题,用纯动态规划的方法来求解的时间复杂度是O(n^2).但是如果加上二叉搜索的方法,那么时间复杂度可以降到nlog(n).  具体分析参考:http://b ...

  3. C#集合--ICollection接口和IList接口

    虽然列举接口提供了一个协议,用于向前的方式遍历集合,但它们没有提供一种机制来确定集合的大小,通过索引访问集合的成员,搜索集合,或修改集合.为了实现这些功能,.NET Framework定义了IColl ...

  4. AchartEngine绘图引擎

    https://code.google.com/p/achartengine/  Code Test代码: /workspace/AChartEngineTest   /workspace/appco ...

  5. MMS关键指标意义&各数值区间意义

    MMS关键指标意义&各数值区间意义 What's MMS MongoDB Management Service (MMS) is a suite of services for managin ...

  6. iOS方法类:CGAffineTransform的使用大概

    CoreGraphics框架中的CGAffineTransform类可用于设定UIView的transform属性,控制视图的缩放.旋转和平移操作: 另称放射变换矩阵,可参照线性代数的矩阵实现方式0. ...

  7. LevelDB(v1.3) 源码阅读之 Arena(内存管理器)

    LevelDB(v1.3) 源码阅读系列使用 LevelDB v1.3 版本的代码,可以通过如下方式下载并切换到 v1.3 版本的代码: $ git clone https://github.com/ ...

  8. 一个基于POP3协议进行邮箱账号验证的类

    最近老陈要针对企业邮箱做一些开发,以对接企业OA神马的,但企业邮箱唯独没有开放账号密码验证功能,很恼火!不得已,翻出早些年的Asp代码改编成了C#类,实现了一个C#下的通过POP3协议进行邮箱账号验证 ...

  9. 让我们一起Go(九)

    前言: 又好久么更新了,无奈公司项目多,自己又接了私活,于是时间更不够了......不过我是不会让它流产的,坚持! 一.Go语言中的函数 终于轮到函数了,其实也没有什么好说的,无非就是一个语法问题,c ...

  10. B2B多商铺初期权限数据库设计

    项目从无到有,两个月了.一期完成. 权限目前还很简单.USER表,ROLE表,RESOURCE表三个. 目前只有两个商铺.id是0的是我们自己,作为后台运维管理,也抽象成一个商铺,id为0.另一个商铺 ...