2014-09-26 138 views
2

我在default.html中聲明瞭一個單獨的AppBar,以便在我的應用程序中使用。如何隱藏Windows Phone 8.1(WinJS)應用程序中的應用程序欄?

在一些頁面上,我需要顯示應用欄和一些需要隱藏AppBar的頁面。

到目前爲止,我的努力找到隱藏和顯示AppBar的方法已經遇到了死衚衕。

在MSDN文檔說:

AppBar.hide method : Hides the app bar on Windows and the secondary command menu on Windows Phone.

因此,該方法僅隱藏AppBar爲Windows而不是一個Windows Phone的項目。

我也試着給display:none做CSS樣式,沒有任何效果。

任何幫助將不勝感激:)

+0

我不確定Winjs,但在C#中,當您設置BottomAppBar = null時,您肯定可以隱藏AppBar。也許你可以嘗試類似的東西。 – Romasz 2014-09-28 19:40:14

+0

是的,我知道如何在C#中做到這一點。但我的要求是WinJS。我完全沉迷於如何做這樣一件簡單的事情。 – 2014-09-29 08:41:04

回答

4

AppBar.Hide隱藏Windows Phone上的輔助命令欄,而不是主AppBar。如果你想讓整個AppBar消失,那麼這不是合適的屬性。

最簡單的方法是在要顯示它的頁面上聲明AppBar,並將它放在不需要的頁面上,但是應該可以通過在頁面上禁用AppBar來隱藏它你不想要它。

我只是修改了HTML AppBar control sample的appbar,commands.js如下文件和appbar隱藏和顯示我點擊隱藏和顯示按鍵:

// These functions are used by the scenario to show and hide elements 
function doShowItems() { 
    document.getElementById('commandsAppBar').winControl.disabled = false; 

    //document.getElementById('commandsAppBar').winControl.showCommands([cmdFavorite, cmdCamera]); 
    document.getElementById('scenarioShowButtons').disabled = true; 
    document.getElementById('scenarioHideButtons').disabled = false; 
} 

function doHideItems() { 
    document.getElementById('commandsAppBar').winControl.disabled = true; 
    //document.getElementById('commandsAppBar').winControl.hideCommands([cmdFavorite, cmdCamera]); 
    document.getElementById('scenarioHideButtons').disabled = true; 
    document.getElementById('scenarioShowButtons').disabled = false; 
} 

我也與單頁導航證實模型在兩頁之間導航。如果你沒有看到appbar隱藏並顯示禁用和啓用時,請確保你正在調用代碼來禁用/啓用appbar。返回到緩存頁面時,PageControl的ready函數可能不會被調用。

+0

好的答案!作品!!!解決方案非常簡單,但我們無法弄清楚。 – 2014-09-30 20:17:19

+0

'當返回到緩存頁面時,可能不會調用PageControl的ready函數'是否有任何關於此主題的內容?我有麻煩在我的堆棧中來回導航,並且正在尋找關於導航內部的更多信息? – 2015-01-13 13:55:48

2

你必須用C#這樣做,你可以簡單地只需鍵入..(如果你的appbar被稱爲應用程序任務欄

ApplicationBar.Visibility = Visibility.Collapsed; 

這將立即隱藏AppBar!如果你想讓你的HTML頁面執行這個動作,它會非常複雜。

乾杯

+0

謝謝,但我想爲WinJS這個。 AppBar控件在WinJS中是不同的,上面的代碼段不適用於WinJS控件。 – 2014-09-29 08:39:36

0

我想你可以試試下面代碼中的一步。

  1. 爲appbar beforeshow
  2. 添加事件偵聽器在之前節目請與特定的頁面名稱 就像一個條件代碼:如果(WinJS.Navigation.location.match( 「test.html的」))
  3. 根據你的條件你可以Disable你的appbar。

一切順利.. !!

+0

將AppBar的'disabled'屬性設置爲'true'似乎隱藏了它,但將其設置爲'false'不會再顯示它。 – 2014-09-29 16:55:46

+0

因此,一旦我設置AppBar'禁用'屬性,我永遠不能啓用它的應用程序中的任何其他頁面。 – 2014-09-29 16:56:35

+0

可以切換禁用屬性。如果你派生頁面卸載方法只需寫入disable = false ..並根據您的需要準備好功能使真或假.. – 2014-09-30 05:52:28

相關問題