【发布时间】:2015-08-01 22:14:43
【问题描述】:
我需要以编程方式将AppBarCommand 添加到AppBar。这曾经适用于 Windows 8.1,但不适用于 Windows 10。我没有收到任何错误,但是当我执行以下代码时,我的应用程序栏是空的。有谁知道是否可以从 WinJS 动态地将AppBarCommands 添加到AppBar 中?如果是这样,怎么办?谢谢。
虽然我的问题发生在一个更大的现有应用程序中,但我从“空白”WinJS 模板中重现了该问题。
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>
【问题讨论】:
-
你能解决这个问题吗?
-
@TheTanic,没有。我不得不放弃程序化的添加和删除。希望他们有一天能修复它。
-
您是否尝试使用数据属性而不是命令? [来自 Appbar] 这对我有用
-
@TheTanic,我对此知之甚少。如果您可以发布有效的答案,我将很乐意接受。
-
你试过了吗?
标签: winjs windows-10 appbar