如果您使用的是空白模板(如您的评论中所述),那么将建议的演示代码放在 onactivate 事件中应该可以工作。下面应该显示从黑框的左上角到右下角的白线。
在 default.html 中:
<body>
<p>Content goes here</p>
<canvas id="can1" width="500" height="500"></canvas>
</body>
在 default.js 中,在 app.onactivated 方法中:
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application has been reactivated from suspension.
// Restore application state here.
}
var myCanvas = document.getElementById("can1");
var myContext = myCanvas.getContext("2d");
myContext.fillStyle = '#000';
myContext.strokeStyle = '#fff';
myContext.fillRect(0, 0, 500, 500);
myContext.lineWidth = 3;
myContext.fill();
myContext.moveTo(0, 0);
myContext.lineTo(500, 500);
myContext.stroke();
args.setPromise(WinJS.UI.processAll());
}
};