我正在尝试完成Windows8开发人员中心的这个教程:http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh452750.aspx
但还没有走出第一步。在我的HTML5文件中有:
<canvas id="can1" width="500" height="500"></canvas>在我的JavaScript文件中有:
var myCanvas = document.getElementById("can1");
var myContext = myCanvas.getContext("2d");我正在使用Visual Studio Express 2012 for Windows8。收到以下错误:"0x800a138f - JavaScript runtime error: Unable to get property 'getContext‘of undefined or null reference“
这正是本教程所要做的。为什么我得到一个错误?
发布于 2012-12-02 14:33:02
如果您正在使用空白模板(如您的评论中所述),那么将建议的演示代码放在onactivated事件中应该是可行的。下面的内容应该从黑盒的左上角到右下角显示白线。
在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());
}
}; https://stackoverflow.com/questions/13664894
复制相似问题