Click here to Skip to main content
15,880,503 members
Articles / Programming Languages / C#

An Introduction to the Silverlight samples in the All-In-One Framework

Rate me:
Please Sign up or sign in to vote.
5.00/5 (26 votes)
12 Dec 2009Ms-PL5 min read 55.1K   2.2K   56  
This article introduces several Silverlight samples in the All-In-One Framework.
'****************************** Module Header ******************************'
' Module Name:                 MainPage.xaml.vb
' Project:                     VBSL3HTMLBridge
' Copyright (c) Microsoft Corporation.
' 
' HTML bridge samples code behind file.
' 
' This source is subject to the Microsoft Public License.
' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
' All other rights reserved.
' 
' History:
' * 10/22/2009 15:21 PM Mog Liang Created
'***************************************************************************'

Imports System.Windows.Browser

Partial Public Class MainPage
    Inherits UserControl
    Public Sub New()
        InitializeComponent()

        ' Register Scriptable Object.
        HtmlPage.RegisterScriptableObject("silverlightPage", Me)

        ' Attach Html Element event.
        HtmlPage.Document.GetElementById("Text2").AttachEvent("onkeyup", New EventHandler(AddressOf HtmlKeyUp))

        AddHandler tb1.TextChanged, AddressOf tb1_TextChanged
        AddHandler tb4.TextChanged, AddressOf tb4_TextChanged
    End Sub

    ' Call javascript when first textbox text changed.
    Private Sub tb1_TextChanged(ByVal sender As Object, ByVal e As TextChangedEventArgs)
        HtmlPage.Window.Invoke("changetext", tb1.Text)
    End Sub

    ' Handle html textbox keyup event.
    Private Sub HtmlKeyUp(ByVal sender As Object, ByVal e As EventArgs)
        Me.tb2.Text = DirectCast(sender, HtmlElement).GetProperty("value").ToString()
    End Sub

    ' Create method for javascript.
    <ScriptableMember()> _
    Public Sub ChangeTB3Text(ByVal text As String)
        tb3.Text = text
    End Sub

    ' Create event allow registering by javascript.
    <ScriptableMember()> _
    Public Event TextChanged As EventHandler(Of TextEventArgs)

    Private Sub tb4_TextChanged(ByVal sender As Object, ByVal e As TextChangedEventArgs)
        Dim myargs = New TextEventArgs()
        myargs.Text = tb4.Text
        RaiseEvent TextChanged(Me, myargs)
    End Sub

End Class

Public Class TextEventArgs
    Inherits EventArgs

    Private _text As String

    <ScriptableMember()> _
    Public Property [Text]() As String
        Get
            Return _text
        End Get
        Set(ByVal value As String)
            _text = value
        End Set
    End Property
End Class


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
China China
Microsoft All-In-One Code Framework delineates the framework and skeleton of Microsoft development techniques through typical sample codes in three popular programming languages (Visual C#, VB.NET, Visual C++). Each sample is elaborately selected, composed, and documented to demonstrate one frequently-asked, tested or used coding scenario based on our support experience in MSDN newsgroups and forums. If you are a software developer, you can fill the skeleton with blood, muscle and soul. If you are a software tester or a support engineer like us, you may extend the sample codes a little to fit your specific test scenario or refer your customer to this project if the customer's question coincides with what we collected.
http://cfx.codeplex.com/

Comments and Discussions