如何在页面片段加载时显示WinJS AppBar?

Cra*_*ker 3 appbar microsoft-metro winjs

我想在页面片段加载时显示AppBar,但是在ready函数中运行的代码没有按预期工作:

function ready(element, options) {
    var appBar = document.getElementById("appBar").winControl;
    appBar.disabled = false;
    appBar.show();
}
Run Code Online (Sandbox Code Playgroud)

页面片段加载时如何显示AppBar?

lou*_*luo 7

假设您正在HTML文件中正确创建appbar.

然后,在该ready方法中,您应该首先调用

WinJS.UI.processAll(elements)
        .then(function () {
              var appbar = document.getElementById("appBar");
              if (appbar) {
                  appbar.winControl.show();
              }
         });
Run Code Online (Sandbox Code Playgroud)

根据MSDN文档,processAll函数"将声明性控件绑定应用于所有元素,从指定的根元素开始." (即将所有html元素转换为WinJS控件)