RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Untapped Silverlight Powers: The Interactive Application : Page 3

Silverlight's good for working with animation, graphics, and videos, but did you know it allows you to do things you can't do elsewhere—even with ASP.NET and AJAX? Learn how to harness that power by building an interactive signature capturing application.

Saving the Signature
Now that you can sign on the canvas, it's time to save the signature to somewhere. But first, add the code shown in Listing 3 to Page.xaml.

Page.xaml should now look like the example shown in Figure 3 (you can view this in Expression Blend 2).

Figure 3. Page.xaml: The page with three buttons and a TextBlock control.

In Page.xaml.vb, define the GetSignatureLines() function so that the coordinates of the signature can be serialized as a string:

    '---returns the signature as a series of lines---
    Private Function GetSignatureLines() As String
        Dim sb As New System.Text.StringBuilder
        '---for each line---
        For i As Integer = 0 To _lines.Count - 1
            '---for each point---
            For Each pt As Point In _lines(i)
                sb.Append(pt.X & "," & pt.Y & "|")
        Return sb.ToString
    End Function
Define the DrawSignature() subroutine so that the signature can be reproduced from the collection of lines, as shown in Listing 4.

This subroutine is needed so that later on you can reproduce a saved signature when you retrieve it from the web service.

Code the MouseLeftButtonDown event handler for the Clear button so that the signature can be cleared from the drawing pad:

'---Clear button---
    Private Sub btnClear_MouseLeftButtonUp( _
       ByVal sender As Object, _
       ByVal e As System.Windows.Input.MouseEventArgs) _
       Handles btnClear.MouseLeftButtonUp

        _lines = New List(Of Object)
        _points = New List(Of Point)

        '---iteratively clear all the signature lines---
        For i As Integer = 0 To SigPad.Children.Count - 2

        txtStatus.Text = "Signature cleared!"

    End Sub
Here, you are simply iteratively removing all the lines in the canvas.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date