|
Silverlight_JsWeb.KeyDown = function() { } Silverlight_JsWeb.KeyDown.prototype = { handleLoad: function(plugIn, userContext, sender) { this.plugIn = plugIn; // 按钮事件挂钩示例: 查找按钮,然后附加事件处理程序 sender.findName("myTextBox").addEventListener("KeyDown", Silverlight.createDelegate(this, this.handleKeyDown)); sender.findName("myTextBox").addEventListener("GotFocus", Silverlight.createDelegate(this, this.handleGotFocus)); sender.findName("myTextBox").addEventListener("LostFocus", Silverlight.createDelegate(this, this.handleLostFocus)); sender.findName("myTextBox").addEventListener("KeyUp", Silverlight.createDelegate(this, this.handleKeyUp)); }, /* keyEventArgs 参数说明: Key: 键值,整型类型。 PlatformKeyCode: 键盘按下的键值,整型类型。This value is the non-portable key code, which is operating system-specific. Shift: 是否按下了 SHIFT 键,Boolean类型. Ctrl: 是否按下了 Ctrl 键,Boolean类型. */ // 键按下的事件处理方法. handleKeyDown: function(sender, keyEventArgs) { var textBlock = sender.findName("myTextBlock"); var msg = "key: " + keyEventArgs.key + "\r\n"; msg += "platformKeycode: " + keyEventArgs.platformKeyCode+ "\r\n"; msg += "shift: " + keyEventArgs.shift+ "\r\n"; msg += "ctrl: " + keyEventArgs.ctrl+ "\r\n";
textBlock.Text = msg; }, //得到输入焦点的处理方法 handleGotFocus: function(sender, keyEventArgs) { sender.findName("myTextBlock").Text = "得到焦点"; }, //失去输入焦点的处理方法 handleLostFocus: function(sender, keyEventArgs) { sender.findName("myTextBlock").Text = "失去焦点"; }, // 键弹起的事件处理方法 handleKeyUp: function(sender, keyEventArgs) { // 判断是否按下 CTRL+V 组合键. if ((keyEventArgs.key == 51) && (keyEventArgs.ctrl == true)) { // 返回插件引用. var plugin = sender.getHost(); // 检测是否是sivlerlight 2.0版. sender.findName("myTextBlock").Text = "Silverlight 2.0: " + plugin.isVersionSupported("2.0"); } } } |