I need to add an AppBarCommand
to an AppBar
programmatically. This used to work on Windows 8.1, but it's not working on Windows 10. I receive no errors, but when I execute the below code, my application bar is empty. Does anyone know if adding AppBarCommand
s to the AppBar
dynamically from WinJS is possible anymore? If so, how can it be done? Thanks.
Although my problem was occurring within a larger existing application, I reproduced the problem from the "Blank" WinJS template.
default.js:
(function () {
"use strict";
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
var appBarDiv = document.createElement("div");
document.body.appendChild(appBarDiv);
var appBar = new WinJS.UI.AppBar(appBarDiv, {});
var command = new WinJS.UI.AppBarCommand(null, { id: "commandID", type:"button", label: "Label", section: "secondary" });
appBar.commands = [command];
}
args.setPromise(WinJS.UI.processAll());
}
};
app.start();
})();
default.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>App1</title>
<!-- WinJS references -->
<link href="WinJS/css/ui-dark.css" rel="stylesheet" />
<script src="WinJS/js/base.js"></script>
<script src="WinJS/js/ui.js"></script>
<!-- App1 references -->
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>
</head>
<body class="win-type-body">
<p>Content goes here</p>
</body>
</html>
Copyright Notice:Content Author:「user1325179」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31766724/add-appbarcommand-to-appbar-in-winjs