2012-10-24 50 views
1

我的應用程序在屏幕底部有一個WinJS AppBar控件。我使用.showOnlyCommands(buttonsToShowArray)來顯示和隱藏ListViewitemSelectionChanged事件中的按鈕。WinJS AppBar按鈕閃爍隱藏

我現在的問題是,當我撥打.showOnlyCommands時,要隱藏的按鈕(或者您可能會說「替換」)將在屏幕頂部閃爍。

我試圖使用微軟的示例應用程序,這不會發生。我試圖用.showCommands + .hideCommands的方法,它是一樣的行爲。請注意,這在Win8的Release Preview版本之前沒有發生。

我不知道發生了什麼事。任何想法?

編輯: 我做了進一步調查,問題發生在hideCommands。假設我在appbar上顯示了3個按鈕。我打電話hideCommands隱藏所有3個按鈕。 3個按鈕的圖標會在應用欄上消失,然後堆積在屏幕的左上角,然後消失。 (即在屏幕的角落將會有3個堆積起來的按鈕閃爍)。

回答

1

當AppBar處於「正在顯示」的過程中時,您可能正在調用showOnlyCommands。我發現,在beforeshow或aftershow處理程序中調用這些方法時會發生這種情況。 Animating your UI的這句引述說明了爲什麼:

使用淡入和淡出動畫來顯示或隱藏瞬態UI或控件。一個例子是在應用欄中,由於用戶交互,新控件可以出現。

示例應用程序在顯示appbar之前顯示/隱藏按鈕。在調用showOnlyCommands之前,您可能正在應用程序欄上調用show。

+0

非常感謝您!我認爲這正是我的情況。我現在正在度假,所以我無法自己測試。但只要我有機會實施它(在2周內),我會將其標記爲正確的答案!非常感謝! –

+0

嘿@ChrisHerring,我正在嘗試你的建議。如果我們不在'beforeShow'上調用'showOnlyCommand',你如何設置當你點擊右鍵時顯示​​哪些按鈕? –

+0

我想我總是可以給appbar一些默認按鈕... –

0

此問題的一個臨時的手段是:

設置按鈕是不可見調用showOnlyCommandsHideCommands之前。

這裏是我用現在的代碼:

/* 
* @param {WinJS.UI.AppBar} appbar winControl 
* @param {Array} array of appbar buttons to be shown 
*/ 
function showOnlyCommands(appbarControl, buttonsToShow) { 
    var toShow = {}; 
    for (var i = 0; i < buttonsToShow.length; i++) { 
     toShow[buttonsToShow[i].id] = true; 
    } 
    for (var i = 0; i < visibleButtonsList.length; i++) { 
     var id = visibleButtonsList[i].id; 
     if (!toShow[id]) { 
      // set the display property of the buttons to be hidden to "none"    
      var button = document.getElementById(id); 
      if (button) { 
       button.style.display = 'none'; 
      } 
     } 
    } 
    // update the visible buttons list 
    visibleButtonsList = buttonsToShow; 
    // Note that we don't need to set the "display" property back for the buttons, 
    // because WinJS.UI.AppBar.showOnlyCommands would set it back internally 
    appbarControl.showOnlyCommands(buttonsToShow); 
}