PageRenderTime 35ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/Visual Studio 2008/CSSL3HTMLBridge/CSSL3HTMLBridge/MainPage.xaml.cs

#
C# | 90 lines | 57 code | 11 blank | 22 comment | 2 complexity | 51c0cf8bddb3aea4673d81035392ba31 MD5 | raw file
  1. /****************************** Module Header ******************************\
  2. Module Name: MainPage.xaml.cs
  3. Project: CSSL3HTMLBridge
  4. Copyright (c) Microsoft Corporation.
  5. HTML bridge samples code behind file.
  6. This source is subject to the Microsoft Public License.
  7. See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
  8. All other rights reserved.
  9. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  10. EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  11. WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  12. \***************************************************************************/
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Net;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Documents;
  19. using System.Windows.Input;
  20. using System.Windows.Media;
  21. using System.Windows.Media.Animation;
  22. using System.Windows.Shapes;
  23. using System.Windows.Browser;
  24. using System.Runtime.Serialization;
  25. using System.ComponentModel;
  26. namespace CSSL3HTMLBridge
  27. {
  28. public partial class MainPage : UserControl
  29. {
  30. public MainPage()
  31. {
  32. InitializeComponent();
  33. // Register Scriptable Object.
  34. HtmlPage.RegisterScriptableObject("silverlightPage", this);
  35. // Attach Html Element event.
  36. HtmlPage.Document.GetElementById("Text2").AttachEvent("onkeyup", new EventHandler(HtmlKeyUp));
  37. tb1.TextChanged += new TextChangedEventHandler(tb1_TextChanged);
  38. tb4.TextChanged += tb4_TextChanged;
  39. }
  40. // Call javascript when first textbox text changed.
  41. private void tb1_TextChanged(object sender, TextChangedEventArgs e)
  42. {
  43. HtmlPage.Window.Invoke("changetext", tb1.Text);
  44. }
  45. // Handle html textbox keyup event.
  46. private void HtmlKeyUp(object sender, EventArgs e)
  47. {
  48. var value = ((HtmlElement)sender).GetProperty("value");
  49. tb2.Text = value.ToString();
  50. }
  51. // Create method for javascript.
  52. [ScriptableMember]
  53. public void ChangeTB3Text(string text)
  54. {
  55. tb3.Text = text;
  56. }
  57. // Create event allow registering by javascript.
  58. [ScriptableMember]
  59. public event EventHandler<TextEventArgs> TextChanged;
  60. void tb4_TextChanged(object sender, TextChangedEventArgs e)
  61. {
  62. var myargs = new TextEventArgs();
  63. myargs.Text = tb4.Text;
  64. if (TextChanged != null)
  65. {
  66. TextChanged(this, new TextEventArgs { Text = tb4.Text });
  67. }
  68. }
  69. }
  70. // Create custom Eventargs containing text property.
  71. public class TextEventArgs : EventArgs
  72. {
  73. [ScriptableMember]
  74. public string Text { set; get; }
  75. }
  76. }