2014年4月3日的微软Build 2014 大会上,Windows Phone 8.1 正式发布。相较于Windows Phone 8,不论从用户还是开发者的角度,都产生了很大的变化。接下来我们会用几篇文章来了解一下这些变化给开发者带来的影响,以及我们如何更好的利用WP8.1 的新特性。

WP8.1 最大的变化就是与Windows Store App 的结合,我们把它们统称为Windows RunTime apps。WP8.1 中的控件位于Windows.UI.XAML.Controls 命名空间下,这和Windows Store App是一致的。

本篇我们先来介绍第一个 WP8.1 的新控件:应用程序栏

应用程序栏想必大家都不陌生,它在WP8 中有很重要的应用,我们也把它叫做ApplicationBar。ApplicationBar 中可以添加按钮和菜单项,我们来看看简单的实现代码:

    <phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar>
<shell:ApplicationBar.Buttons>
<shell:ApplicationBarIconButton Text="Btn1" IconUri="***.png"/>
<shell:ApplicationBarIconButton Text="Btn2" IconUri="***.png">
</shell:ApplicationBar.Buttons>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Text="Menu Item 1"/>
<shell:ApplicationBarMenuItem Text="Menu Item 2"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

这个例子里,ApplicationBar 包含了两个按钮和两个菜单项。下面我们来看在WP8.1 中如何实现应用程序栏:

在Windows Store App 中,应用程序栏分为两种,TopAppBar 和 BottomAppBar,分别用做顶部导航栏和底部命令栏。而在WP8.1 中只有BottomAppBar,它起到的作用跟WP8 中的ApplicationBar是相同的。BottomAppBar 可以包含CommandBar, 而CommandBar 中可以使用两种命令元素,主命令元素和辅助命令元素。这两种元素在作用上类似于WP8 中的按钮和菜单项。来看看代码:

    <Page.BottomAppBar>
<CommandBar IsSticky="True">
<CommandBar.PrimaryCommands>
<AppBarButton Icon="ZoomOut" IsCompact="False" Label="ZoomOut"/>
<AppBarButton IsCompact="True">
<AppBarButton.Icon>
<PathIcon Data="F1 M 20, 10L 10,30L 30,30"/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton IsCompact="True">
<AppBarButton.Icon>
<BitmapIcon UriSource="Assets/setting.png"/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarToggleButton IsCompact="False" Label="Omega" IsChecked="True">
<AppBarToggleButton.Icon>
<FontIcon FontFamily="Candara" Glyph="Ω"/>
</AppBarToggleButton.Icon>
</AppBarToggleButton>
</CommandBar.PrimaryCommands>
<CommandBar.SecondaryCommands>
<AppBarButton Label="Test01"/>
<AppBarButton Label="Test02"/>
</CommandBar.SecondaryCommands>
</CommandBar>
</Page.BottomAppBar>

我们为CommandBar定义了两种集合元素,PrimaryCommands 和 SecondaryCommands,集合中的元素可以是AppBarButton 或 AppBarToggleButton。

来看看AppBarButton中几个重要的属性:

* Icon:用于显示应用程序栏按钮的图形内容。它有几种表现方式:

  • SymbolIcon - 基于Segoe UI Symbol 字体的字型预定义列表
  • FontIcon - 基于指定字体系列的字型
  • BitmapIcon - 基于指定Uri的位图图像文件
  • PathIcon - 基于路径数据

* Label:程序栏上显示的文字说明

* IsCompact:布尔值,指示是否显示不带标签且边距已缩小的按钮

再来看看AppBarToggleButton, 它与AppBarButton 的不同在于他可以有选中状态:

* IsChecked - 布尔值,选中为True,未选中为False,否则为null。默认为False。

我们在示例中对这几种属性做了演示,PrimaryCommands 中的四个按钮分别采用了四种表现方式,另外结合了Label、IsChecked 和 IsCompact 的属性区别。其中SecondaryCommands 中使用Label 属性来显示信息(而且字母不会像WP8 那样被转换为小写字母)。Icon 和 IsCompact 属性并没有体现。来看看运行效果图:

这样我们就把Windows Phone 8.1 中的应用程序栏的变化演示完了。总体来说新的应用程序栏给我们带来了更多的可选择性和便利,按钮可以有多种表现方式,而不是单一的图片方式;按钮可选择是否显示文字标签,等等。接下来的几篇我会继续介绍Windows Phone 8.1 中的新控件,谢谢大家。

Windows Phone 8.1 新特性 - 控件之应用程序栏的更多相关文章

  1. Windows Phone 8.1 新特性 - 控件之列表选择控件

    本篇我们来介绍Windows Phone 8.1 新特性中的列表选择控件. 在Windows Phone 8 时代,大家都会使用 LongListSelector 来实现列表选择控件,对数据进行分组显 ...

  2. Windows Phone 8.1 新特性 - 控件之FlipView

    本篇为大家介绍 Windows Phone 8.1 中新增的 FlipView 控件,它的中文名字叫做:翻转视图. 虽然听起来有点拗口,但是它的用途大家一定不会陌生.在 Windows Phone 8 ...

  3. 与众不同 windows phone (34) - 8.0 新的控件: LongListSelector

    [源码下载] 与众不同 windows phone (34) - 8.0 新的控件: LongListSelector 作者:webabcd 介绍与众不同 windows phone 8.0 之 新的 ...

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

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

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

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

  6. 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView

    [源码下载] 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...

  7. 与众不同 windows phone (51) - 8.1 新增控件: DatePickerFlyout, TimePickerFlyout

    [源码下载] 与众不同 windows phone (51) - 8.1 新增控件: DatePickerFlyout, TimePickerFlyout 作者:webabcd 介绍与众不同 wind ...

  8. 重新想象 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 ...

  9. Windows Phone 8.1新特性 - 应用商店启动协议

    Windows Phone 8.1 Preview SDK 发布也有几个月了,之前断断续续也写过几篇 Windows Phone 8.1 新特性的文章,今天给大家介绍一下应用商店启动协议相关的知识. ...

随机推荐

  1. click事件

    click事件是可以多次绑定的,如果绑定多次就会执行多次,因此再不需要重复执行的情况下,就需要使用unbind对事件进行解绑

  2. ASP.NET Page对象各事件执行顺序(转)

    很久没写 asp.net 的东西了,search 了一下 page 的事件执行顺序,找到如下的东西,仅仅做记录用 Page.PreInit 在页初始化开始时发生 Page.Init 当服务器控件初始化 ...

  3. 关于UIView的autoresizingMask属性的研究【转】

    在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. 1 2 3 4 5 6 7 8 9 enum  ...

  4. Appium for Mac 环境准备篇

    之前写过一篇Appium for windows的文章,因为是09年的T400,启动Android模拟器的时候死机三次,那就公司申请台Macbook air吧,15寸的Macbook Pro实在太重了 ...

  5. lua 中的面向对象

    lua 是一种脚步语言,语言本身并不具备面向对象的特性. 但是我们依然可以利用语言的特性,模拟出面向对象的特性. 面向对象的特性通常会具备:封装,继承,多态的特性,如何在lua中实现这些特性,最主要的 ...

  6. 用移动智能设备访问Ossim系统

    用移动智能设备访问Ossim系统 下面我们使用iPad,iPhone访问ossim系统的效果. 高清视频:http://www.tudou.com/programs/view/TikMZ1z1ELw ...

  7. rdesktop tsclient

  8. 关键字static和this

    1.this关键字 this:代表当前对象,就是代表所在函数所属类的引用.哪个对象调用了this所在的函数,this就代表哪个对象. this关键字也可以用于在构造函数中调用其他构造函数,此时要注意, ...

  9. linux grep命令详解

    linux grep命令详解 简介 grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来 ...

  10. JSP调用JAVA方法小例子

    用JAVA编写的函数 package doc; //定义一个包 public class Dy { //定义一个类 public static int Sub(int x,int y){ //定义函数 ...