新聞中心
將新功能添加到 Windows 應(yīng)用商店應(yīng)用,例如自定義命令和和增強(qiáng)導(dǎo)航支持,以及 Windows 8.1 Preview 中的全新 HTML 和 JavaScript 控件。 對(duì)現(xiàn)有控件的更新可使這些控件更易于使用和添加更多功能,如拖放操作支持。 這些新控件和控件更新讓創(chuàng)建功能齊全的應(yīng)用變得***的簡(jiǎn)單。

成都網(wǎng)絡(luò)公司-成都網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站10余年經(jīng)驗(yàn)成就非凡,專業(yè)從事成都做網(wǎng)站、成都網(wǎng)站建設(shè),成都網(wǎng)頁(yè)設(shè)計(jì),成都網(wǎng)頁(yè)制作,軟文發(fā)布平臺(tái),廣告投放平臺(tái)等。10余年來(lái)已成功提供全面的成都網(wǎng)站建設(shè)方案,打造行業(yè)特色的成都網(wǎng)站建設(shè)案例,建站熱線:18982081108,我們期待您的來(lái)電!
新控件和控件更新
Windows 8.1 Preview 和適用于 JavaScript 2.0 Preview 的 Windows 庫(kù)中引入了以下新控件和功能:
- AppBarCommand
- BackButton
- Hub(中心)
- ItemContainer
- NavBar
- Repeater
- WebView
Windows 8.1 Preview 和適用于 JavaScript 2.0 Preview 的 Windows 庫(kù)中包括這些現(xiàn)有控件的更新:
- 對(duì) ListView 的拖放操作支持
- 對(duì) ListView 中的項(xiàng)目重新排序
- 新 ListView 布局:CellSpanningLayout
- 其他 ListView 更新
- 其他 Windows JavaScript 庫(kù)更新
使用適用于 JavaScript 2.0 Preview 的 Windows 庫(kù)
新的 Microsoft Visual Studio 2013 Preview 項(xiàng)目中會(huì)自動(dòng)包含適用于 JavaScript 2.0 Preview 的 Windows 庫(kù)。若要在使用 Windows 8 創(chuàng)建的項(xiàng)目中使用適用于 JavaScript 2.0 Preview 的 Windows 庫(kù),請(qǐng)將你的現(xiàn)有適用于 JavaScript 1 的 Windows 庫(kù)引用替換為
對(duì)適用于 JavaScript 2.0 Preview 的 Windows 庫(kù)的引用。
Visual Studio 2013 Preview 可以自動(dòng)為你升級(jí)項(xiàng)目,你也可以手動(dòng)完成以下更新:
- 向項(xiàng)目中添加對(duì)適用于 JavaScript 的 Windows 8.1 庫(kù)的引用。
- 在你的應(yīng)用清單中,將 OSMinVersion 和 OSMaxVersionTested 值更新為 6.3.0:
6.3.0 6.3.0
AppBarCommand
在 Windows 8.1 Preview 中,你可以使用一種名為“內(nèi)容”的新型 AppBarCommand 在使用 JavaScript 的 Windows 應(yīng)用商店應(yīng)用中創(chuàng)建自定義應(yīng)用欄命令。
此功能通過(guò)允許你在 commands 布局中放置自定義內(nèi)容,從而簡(jiǎn)化了使用自定義內(nèi)容創(chuàng)建應(yīng)用欄的過(guò)程。你可以利用對(duì)使用自定義內(nèi)容的應(yīng)用欄命令的全面內(nèi)置支持,包括鍵盤操作、命令定位,以及用于動(dòng)態(tài)顯示和隱藏命令的動(dòng)畫。
放入到 commands 布局中后,內(nèi)容類型 AppBarCommand 支持很多與默認(rèn)應(yīng)用欄命令相同的功能。
- 在默認(rèn)應(yīng)用欄命令和自定義 AppBarCommand 之間已啟用鍵盤操作(Tab 鍵、箭頭鍵、Home 鍵以及 End 鍵)。
- 新的內(nèi)容類型 AppBarCommand 能夠正常使用應(yīng)用欄可伸縮性。應(yīng)用在被縮小之后會(huì)動(dòng)態(tài)放棄文本標(biāo)簽。
BackButton
Windows 8.1 Preview 和適用于 JavaScript 2.0 Preview 的 Windows 庫(kù)會(huì)以應(yīng)用的控件形式向平臺(tái)中添加更多導(dǎo)航支持。這些控件之一就是 BackButton。
BackButton 為你提供一個(gè)向自己的應(yīng)用中添加向后導(dǎo)航功能的簡(jiǎn)單方法。創(chuàng)建一個(gè) BackButton 控件很簡(jiǎn)單。
BackButton 會(huì)自動(dòng)檢查導(dǎo)航堆棧,以確定用戶是否可以向后導(dǎo)航。如果沒(méi)有可向后導(dǎo)航的內(nèi)容,此按鈕會(huì)自動(dòng)禁用。當(dāng)用戶單擊此按鈕或使用鍵盤快捷方式(如 Alt+ 向左鍵或 BrowserBack 鍵)時(shí),它會(huì)自動(dòng)調(diào)用 WinJS.Navigation.back 函數(shù)以向后導(dǎo)航。你無(wú)需編寫任何代碼。
Hub(中心)
為了幫助提供更一致的導(dǎo)航體驗(yàn),Windows 8.1 Preview 和適用于 JavaScript 2.0 Preview 的 Windows 庫(kù)添加了 Hub 控件。
很多 Windows 應(yīng)用商店應(yīng)用都使用中心導(dǎo)航模式,即一種分層的導(dǎo)航系統(tǒng)。此模式最適合具有大量?jī)?nèi)容或許多不同部分內(nèi)容供用戶瀏覽的應(yīng)用。
中心設(shè)計(jì)的實(shí)質(zhì)是將內(nèi)容分為不同的部分和不同級(jí)別的詳細(xì)信息。 中心頁(yè)是用戶進(jìn)入應(yīng)用的入口點(diǎn)。此處的內(nèi)容顯示在一個(gè)水平平移或垂直平移的平移視圖中,這樣用戶一眼就能看見(jiàn)新增內(nèi)容和可用功能。 中心由不同類別的內(nèi)容構(gòu)成,每個(gè)類別映射到應(yīng)用的部分頁(yè)中。每個(gè)部分都應(yīng)該顯示內(nèi)容或功能。中心應(yīng)該提供許多可以看到的變化,吸引用戶,并將他們吸引到應(yīng)用的各個(gè)部分。
有了 Windows 8.1 Preview,Hub 控件可使創(chuàng)建中心頁(yè)更容易。若要開始快速創(chuàng)建帶有 Hub 頁(yè)的應(yīng)用,請(qǐng)使用 Visual Studio 2013 Preview 中的“中心應(yīng)用”模板。
創(chuàng)建中心
若要?jiǎng)?chuàng)建中心,你需要為中心包含的每個(gè)部分添加一個(gè) Hub 控件和一個(gè) HubSection 對(duì)象。每個(gè) HubSection 都可以包含任何類型的內(nèi)容,包括其他 Windows JavaScript 庫(kù)控件。你可以使用 header 屬性來(lái)指定節(jié)標(biāo)題。部分頭文件可為靜態(tài)或交互文件。交互式頭文件顯示可隱藏的 V 形圖標(biāo),并在用戶與它們交互時(shí)提升事件。
以下示例定義了一個(gè)包含三個(gè)部分的 Hub。
hubPage
- Hub example
![]()
- data-win-options="{ onheaderinvoked: HubPage.section2HeaderNavigate }">
![]()
- layout: {type: WinJS.UI.ListLayout2},
- selectionMode: 'none',
- itemTemplate: select('.section2 .itemTemplate'),
- itemDataSource: HubPage.section2DataSource,
- oniteminvoked: HubPage.section2ItemNavigate
- }">
![]()
![]()
![]()
![]()
該代碼創(chuàng)建此頁(yè)面。
單擊第二個(gè)標(biāo)題時(shí),應(yīng)用會(huì)轉(zhuǎn)到第二頁(yè)。
以下代碼執(zhí)行導(dǎo)航。
- (function () {
- "use strict";
- var nav = WinJS.Navigation;
- var session = WinJS.Application.sessionState;
- var util = WinJS.Utilities;
- // Get the groups used by the data-bound sections of the hub.
- var section2Group = Data.resolveGroupReference("group1");
- var section5Group = Data.resolveGroupReference("group6");
- WinJS.UI.Pages.define("/pages/hub/hub.html", {
- // This function is called whenever a user navigates to this page. It
- // populates the page elements with the app's data.
- ready: function (element, options) {
- var hub = element.querySelector(".hub").winControl;
- hub.onloadingstatechanged = function (args) {
- if (args.srcElement === hub.element && args.detail.loadingState === "complete") {
- this._hubReady(hub);
- hub.onloadingstatechanged = null;
- }
- }.bind(this);
- hub.onheaderinvoked = function (args) {
- args.detail.section.onheaderinvoked(args);
- };
- // TODO: Initialize the page here.
- },
- unload: function () {
- // TODO: Respond to navigations away from this page.
- session.hubScroll = document.querySelector(".hub").winControl.scrollPosition;
- },
- updateLayout: function (element, viewState, lastViewState) {
- ///
- // TODO: Respond to changes in viewState.
- },
- _hubReady: function (hub) {
- ///
- WinJS.Resources.processAll();
- if (typeof session.hubScroll === "number") {
- hub.scrollPosition = session.hubScroll;
- }
- // TODO: Initialize the hub sections here.
- },
- });
- function createHeaderNavigator(group) {
- return util.markSupportedForProcessing(function (args) {
- nav.navigate("/pages/section/section.html", { title: this.header, groupKey: group.key });
- });
- }
- function createItemNavigator(group) {
- var items = Data.getItemsFromGroup(group);
- return util.markSupportedForProcessing(function (args) {
- var item = Data.getItemReference(items.getAt(args.detail.itemIndex));
- nav.navigate("/pages/item/item.html", { item: item });
- });
- }
- function getItemsDataSourceFromGroup(group) {
- return Data.getItemsFromGroup(group).dataSource;
- }
- WinJS.Namespace.define("HubPage", {
- section2DataSource: getItemsDataSourceFromGroup(section2Group),
- section2HeaderNavigate: createHeaderNavigator(section2Group),
- section2ItemNavigate: createItemNavigator(section2Group),
- section5DataSource: getItemsDataSourceFromGroup(section5Group),
- section5ItemNavigate: createItemNavigator(section5Group)
- });
- })();
你甚至可使用 Hub 控件和 SemanticZoom 控件。有關(guān)此控制和更多的示例,請(qǐng)參閱 HTML 中心控件示例。
ItemContainer
新的 ItemContainer 控件可簡(jiǎn)化創(chuàng)建交互式元素的過(guò)程,這些元素提供了輕掃、拖放以及懸停功能。只需將你的內(nèi)容放到 ItemContainer 中即可。ItemContainer 可以包含標(biāo)準(zhǔn) HTML 元素,甚至其他 Windows JavaScript 庫(kù)控件。
ItemContainer 很靈活,從而使其非常適合很多用途,如創(chuàng)建內(nèi)容豐富的復(fù)選框組、導(dǎo)航按鈕,以及購(gòu)物車表示。
當(dāng)你希望顯示項(xiàng)目,但又不需要使用全部 ListView 功能時(shí),可以使用 ItemContainer 控件。
使用 ItemContainer
以下示例將創(chuàng)建兩個(gè) ItemContainer 對(duì)象,并將它們的 tapBehavior 屬性設(shè)置為 toggleSelect 以便可以被選擇。
- data-win-control="WinJS.UI.ItemContainer"
- data-win-options="{tapBehavior: 'toggleSelect'}"
- style="width: 300px;">
- style="margin-bottom: 5px;">
- Banana
![]()
Frozen yogurt- data-win-control="WinJS.UI.ItemContainer"
- data-win-options="{tapBehavior: 'toggleSelect'}"
- style="width: 300px;">
- style="margin-bottom: 5px;">
- Strawberry
![]()
Ice cream
你還可以將一個(gè) ItemContainer 與一個(gè) Repeater 控件一起使用以從 List 生成項(xiàng)目:只需將 ItemContainer 放入你的 Template 控件中即可。
- data-win-control="WinJS.UI.ItemContainer"
- data-win-options="{tapBehavior: WinJS.UI.TapBehavior.toggleSelect}"
- style="width: 300px;">
- style=" margin: 10px; padding: 10px; background-color: lightgray">
- style="margin-bottom: 5px;"
- data-win-bind="textContent: title">
![]()
- data-win-options="{data: ItemContainerExample.flavorList,
- template: select('#itemTemplate')}">
以下示例定義了數(shù)據(jù)源。
- (function () {
- "use strict";
- var basicList = new WinJS.Binding.List(
- [
- { title: "Banana blast", desc: 'Frozen yogurt', image: '/images/60Banana.png' },
- { title: "Strawberry swirl", desc: 'Ice cream', image: '/images/60Strawberry.png' },
- { title: "Magnificant mint", desc: 'Frozen yogurt', image: '/images/60Mint.png' },
- { title: "Lemon lift", desc: 'Frozen yogurt', image: '/images/60Lemon.png' }
- ]);
- WinJS.Namespace.define("ItemContainerExample",
- {
- flavorList: basicList
- });
- })();
默認(rèn)情況下可以選擇項(xiàng)目。若要禁用選擇,請(qǐng)將 ItemContainer 控件的 selectionDisabled 屬性設(shè)置為 true。
NavBar
[立即獲取 HTML NavBar 控件示例。]
Windows 8.1 Preview 和適用于 JavaScript 2.0 Preview 的 Windows 庫(kù)中引入了以下新控件,以幫助你提供一致且可預(yù)測(cè)的導(dǎo)航體驗(yàn):WinJS.UI.NavBar 控件。
NavBar 類似于專用于導(dǎo)航命令的 AppBar。(實(shí)際上,NavBar 是 AppBar 的子類。)它可以包含一系列簡(jiǎn)單的鏈接,也可以包含分類顯示的多個(gè)級(jí)別的鏈接。你可以使用以下方法填充 NavBar:硬編碼條目、以編程方式更新它,或者使用數(shù)據(jù)綁定。
NavBar 會(huì)在用戶需要時(shí)顯示在應(yīng)用屏幕的頁(yè)首。用戶可以通過(guò)以下方式調(diào)用 NavBar:執(zhí)行邊緣輕掃、按 Windows 徽標(biāo)鍵 + Z,或者右鍵單擊。
NavBar 還支持垂直布局和拆分的導(dǎo)航項(xiàng)(具有子導(dǎo)航選項(xiàng)的導(dǎo)航項(xiàng))。NavBar 是一個(gè)高度可自定義的對(duì)象:你可以使用級(jí)聯(lián)樣式表 (CSS) 設(shè)計(jì) NavBar 及其內(nèi)容的幾乎所有方面的樣式,還可以創(chuàng)建自定義導(dǎo)航項(xiàng)。
創(chuàng)建 NavBar
NavBar 包括三個(gè)組件:
- NavBar 自身。
- NavBarContainer 對(duì)象,它包含導(dǎo)航項(xiàng)(NavBarCommand 對(duì)象),并支持分頁(yè)以及平移和滾動(dòng)。在一個(gè) NavBar 中可以包含一個(gè)或多個(gè) NavBarContainer 對(duì)象??梢允褂?NavBarContainer 對(duì)象來(lái)定義導(dǎo)航選項(xiàng)組。
- 一個(gè)或多個(gè) NavBarCommand 對(duì)象。 這些是用戶單擊可以導(dǎo)航的內(nèi)容。
若要啟用導(dǎo)航,你可以設(shè)置 NavBarCommand 對(duì)象的 location 屬性。用戶單擊命令時(shí),WinJS.Navigation.navigated 事件啟動(dòng)。 使用此事件導(dǎo)航到指定的位置。
也可以在 NavBar 上注冊(cè) oninvoked 事件,并使用你的事件處理程序執(zhí)行導(dǎo)航操作。
以下示例顯示了一個(gè)包含兩個(gè)導(dǎo)航項(xiàng)的簡(jiǎn)單 NavBar。
- label: 'Home',
- icon: WinJS.UI.AppBarIcon.home,
- location: '/html/home.html',
- splitButton: false
- }">
- label: 'Your apps',
- icon: WinJS.UI.AppBarIcon.favorite,
- location: '/html/yourapps.html',
- splitButton: false
- }">
NavBar 如下所示。
可創(chuàng)建包含子 NavBarCommand 對(duì)象的 NavBarCommand。要這樣做,請(qǐng)將父 NavBarCommand 對(duì)象的 splitButton 屬性設(shè)置為 true,然后使用 splittoggle 事件顯示一個(gè)包含子 NavBarCommand 對(duì)象的 Flyout。此處是其***個(gè)部分的示例代碼。
- data-win-options="{ label: 'Home', icon: 'url(../images/homeIcon.png)' }">
- data-win-options="{ label: 'Favorite', icon: WinJS.UI.AppBarIcon.favorite, splitButton: 'true' }">
- data-win-options="{ label: 'Your account', icon: WinJS.UI.AppBarIcon.people }">
- data-win-options="{ placement: 'bottom' }">
- data-win-options="{ label: 'Family' }">


咨詢
建站咨詢
