Windows 8.1 应用再出发 (WinJS) - 几种新增控件(1)
Windows 8.1 和 WinJS 引入了以下新控件和功能,分别是:AppBarCommand、BackButton、Hub、ItemContainer、NavBar、Repeater、WebView。
本篇我们先来介绍 AppBarCommand、BackButton、Hub、ItemContainer,其余三种放在下一篇中介绍。
1. AppBarCommand
Windows 8.1 加入了AppBarCommand 控件来创建自定义应用栏命令。AppBarCommand可以是这几种类型:button、toggle、flyout、separator 和 content。我们来看一个例子:
<body>
<div id="exampleFlyout" data-win-control="WinJS.UI.Flyout" aria-label="{Example flyout}">
<div>This is an example AppBarCommand of type 'flyout'.</div>
</div>
<div id="appBar" data-win-control="WinJS.UI.AppBar" data-win-options="{placement:'bottom'}">
<div data-win-control="WinJS.UI.AppBarCommand"
data-win-options="{ id: 'list', type: 'content', label:'List', section: 'selection'}">
<select class="options">
<option>Option1</option>
<option>Option2</option>
<option>Option3</option>
<option>Option4</option>
</select>
</div>
<div data-win-control="WinJS.UI.AppBarCommand"
data-win-options="{ id: 'textfield', type: 'content', label:'Text field', section: 'selection' }">
<input type="text" value="Text" />
</div>
<button data-win-control="WinJS.UI.AppBarCommand"
data-win-options="{id:'flyoutButton', type:'flyout', label:'Flyout', icon:'document', section: 'selection',
flyout:select('#exampleFlyout')}"/>
<button data-win-control="WinJS.UI.AppBarCommand"
data-win-options="{id:'cmdToggle', type:'toggle', label:'Toggle', icon:'video', section:'global', tooltip:'Toggle'}"/>
<hr data-win-control="WinJS.UI.AppBarCommand"
data-win-options="{id:'separator', type:'separator', section:'global'}" />
<button data-win-control="WinJS.UI.AppBarCommand"
data-win-options="{id:'helpButton', type: 'button', label:'Help', tooltip:'Help', icon:'help', section:'global'}"/>
</div>
</body>
在这个例子中,我们演示了在页面底部的AppBar中 button、toggle 等五种类型的AppBarCommand。AppBar 中的 AppBarCommand 之间支持键盘操作,比如Tab, Enter, 箭头,Home 和 End 键。
另外应用缩小到半屏宽后,文本标签不会再显示。这个XAML中的特性是相似的。
2. BackButton
顾名思义,BackButton 可以简单的在应用中添加后退导航功能,BackButton 会自动检查导航堆栈,来决定是否让用户后退。如果没有后退导航的内容,按钮会自动禁用。按钮会自动调用WinJS.Navigation.back函数来完成导航动作,无需另写代码。来看看代码写法:
<button data-win-control="WinJS.UI.BackButton" ></button>
3. Hub
Windows 8.1 在XAML 和WinJS 中加入了Hub,也就是中心控件。它可以帮我们更轻松的创建中心页,例如应用商店的首页就是一个中心页。Hub控件可以包含多个HubSection对象,每个HubSection可以包含内容和标题。标题可以选择是否隐藏 > 图标,显示时,标题可以交互。来看看例子:
<div class="hub" data-win-control="WinJS.UI.Hub">
<div class="section1" data-win-control="WinJS.UI.HubSection" data-win-options="{ isHeaderStatic: true }" data-win-res="{ winControl: {'header': 'Section1'} }">
<img src="/images/gray.png" width="420" height="280" />
<div class="subtext win-type-x-large" data-win-res="{ textContent: 'Section1Subtext' }"></div>
<div class="win-type-medium" data-win-res="{ textContent: 'DescriptionText' }"></div>
<div class="win-type-small">
<span data-win-res="{ textContent: 'Section1Description' }"></span>
<span data-win-res="{ textContent: 'Section1Description' }"></span>
<span data-win-res="{ textContent: 'Section1Description' }"></span>
</div>
</div> <div class="section2" data-win-control="WinJS.UI.HubSection" data-win-res="{ winControl: {'header': 'Section2'} }">
<div class="item-title win-type-medium" data-win-res="{ textContent: 'Section2ItemTitle', }"></div>
<div class="article-header win-type-x-large" data-win-res="{ textContent: 'Section2Subtext' }"></div>
<div class="win-type-xx-small" data-win-res="{ textContent: 'Section2ItemSubTitle' }"></div>
<div class="win-type-small">
<span data-win-res="{ textContent: 'Section2Description' }"></span>
<span data-win-res="{ textContent: 'Section2Description' }"></span>
<span data-win-res="{ textContent: 'Section2Description' }"></span>
<span data-win-res="{ textContent: 'Section2Description' }"></span>
<span data-win-res="{ textContent: 'Section2Description' }"></span>
<span data-win-res="{ textContent: 'Section2Description' }"></span>
</div>
</div>
</div>
4. ItemContainer
ItemContainer 可以为元素提供pressed,swiped 和 dragged 功能,把我们需要的元素加入到ItemContainer 中即可。例如我们需要显示元素,又不需要用到ListView 中全部功能时,就可以选择ItemContainer控件。其中tapBehavior 属性设置为toggleSelect 时,对象可以被选择。设置为none,并且selectionDisabled 设置为 true 时,元素不能被选择。我们来看一个简单的例子:
<div style="margin: 150px 10px 20px 150px; width: 200px;" id="item1"
data-win-control="WinJS.UI.ItemContainer"
data-win-options="{tapBehavior: 'toggleSelect'}">
<div style="margin: 10px; padding: 10px; background-color: gray">
<div class="win-type-x-large"
style="margin-bottom: 5px;">
晴天
</div>
<img src="/images/d00.gif">
<div>晴天</div>
</div>
</div>
<div style="margin: 250px 10px 150px 150px; width: 200px;" id="item2"
data-win-control="WinJS.UI.ItemContainer"
data-win-options="{tapBehavior: 'none', selectionDisabled: 'true'}">
<div style="margin: 10px; padding: 10px; background-color: gray;">
<div class="win-type-x-large"
style="margin-bottom: 5px;">
多云
</div>
<img src="/images/d01.gif">
<div>多云</div>
</div>
</div>
这里我们并没有对css做调整,主要为了演示第一个元素是可以被选择的,而第二个元素则没有选中状态。
到这里我们就把 AppBarCommand、BackButton、Hub、ItemContainer 四种控件介绍完了,下一篇会介绍剩余三种控件,谢谢。
Windows 8.1 应用再出发 (WinJS) - 几种新增控件(1)的更多相关文章
- Windows 8.1 应用再出发 (WinJS) - 几种新增控件(2)
上篇我们介绍了Windows 8.1 和 WinJS 中新增控件中的 AppBarCommand.BackButton.Hub.ItemContainer,本篇我们接着来介绍 NavBar.Repea ...
- Windows 8.1 应用再出发 (WinJS) - 创建一个简单项目
前面几篇我们介绍了如何利用 C# + XAML 完成Windows Store App 功能的实现,接下来的几篇我们来看看如何利用 Html + WinJS 来完成这些功能. 本篇我们使用WinJS ...
- Windows 8.1 应用再出发 - 几种新增控件(1)
Windows 8.1 新增的一些控件,分别是:AppBar.CommandBar.DatePicker.TimePicker.Flyout.MenuFlyout.SettingsFlyout.Hub ...
- Windows 8.1 应用再出发 - 几种新增控件(2)
本篇我们接着来介绍Windows 8.1 的新增控件,分别是:Flyout.MenuFlyout.SettingsFlyout.Hub 和 Hyperlink. 1. Flyout Flyout被称为 ...
- Windows 8.1 应用再出发 - 几种布局控件
本篇为大家介绍Windows 商店应用中几种布局控件的用法.分别是Canvas.Grid.StackPanel 和 VariableSizedWrapGrid. 1. Canvas Canvas使用绝 ...
- 与众不同 windows phone (49) - 8.1 新增控件: 概述, ContentDialog, MapControl
[源码下载] 与众不同 windows phone (49) - 8.1 新增控件: 概述, ContentDialog, MapControl 作者:webabcd 介绍与众不同 windows p ...
- Windows Phone中的几种集合控件
前言 Windows Phone开发过程中不可避免的就是和集合数据打交道,如果之前做过WP App的开发的话,相信你已经看过了各种集合控件的使用.扩展和自定义.这些个内容在这篇博客里都没有,那么我们今 ...
- Delphi一共封装(超类化)了8种Windows基础控件和17种复杂控件
超类化源码: procedure TWinControl.CreateSubClass(var Params: TCreateParams; ControlClassName: PChar); con ...
- Windows 8.1中WinRT的变化(一)——新增控件
这次WinRT的变化还是不小的,就拿新增控件来说,就有如下几种: AppBar 控件 我以前写过一篇文章接受过如何在WinRT程序中快速创建Metro风格图标,现在MS已经把他们标准化了,就不用我们自 ...
随机推荐
- Dynamics Webservice Call with Credential
Dynamics Webservice call with credential /// <summary> ///WebServiceHelper 的摘要说明 /// </summ ...
- SmartWiki文档在线管理系统简介
简介 SmartWiki是一款针对IT团队开发的简单好用的文档管理系统.可以用来储存日常接口文档,数据库字典,手册说明等文档.内置项目管理,用户管理,权限管理等功能,能够满足大部分中小团队的文档管理需 ...
- 【整理】更改MSSQL默认字符集
记录所有应用到 SQL Server 实例和当前排序规则的 Service Pack 和修补程序: SELECT SERVERPROPERTY('ProductVersion ') AS Produc ...
- JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作
一.Iframe 篇 公共部分 //父对象得到子窗口的值 //ObjectID是窗口标识,ContentID是元素ID function GetValue(ObjectID,ContentID) { ...
- xml 中转意字符&\/使用方法
所有 XML 元素都须有关闭标签 在 HTML,经常会看到没有关闭标签的元素: <p>This is a paragraph <p>This is another paragr ...
- 使用Autofac在MVC中实现IOC
var builder = new ContainerBuilder(); //注册DispatchService类型到工厂中 builder.RegisterType<DispatchServ ...
- 开发中model,entity和pojo的区别
Entity接近原始数据,Model接近业务对象- Entity:是专用于EF的对数据库表的操作, Model:是为页面提供数据和数据校验的,所以两者可以并存 POJO:POJO是Plain Ordi ...
- Bootstrap修改input file默认样式
html部分 <div class="form-group"> <label class="col-sm-3 control-label"&g ...
- linux vim 替换指定字符为回车
有个问题,想要知道逗号分隔的字符串 example: aaa,bbb,ccc 分隔后的个数 1 将 aaa,bbb,ccc 替换成 aaa bbb ccc 方法: :%s/,/^M/g ^M是用 ...
- node.js入门及express.js框架
node.js介绍 javascript原本只是用来处理前端,Node使得javascript编写服务端程序成为可能.于是前端开发者也可以借此轻松进入后端开发领域.Node是基于Google的V8引擎 ...