<Canvas>
<Canvas x:Name='SigPad' Width='404' Height='152'
Canvas.Left='8' Canvas.Top='9' Background='#FFF4F60C'>
<Rectangle Width='404' Height='152' Fill='#FFF1F8DB'
Stroke='#FF000000' StrokeThickness='3'/>
</Canvas>
</Canvas>
</UserControl>
Page.xaml
should now look like Figure 19-71.

Figure 19-71
In Page.xaml.cs
, import the following namespaces:
using System.IO.IsolatedStorage;
using System.IO;
Add the following lines to the Page() constructor:
public Page() {
InitializeComponent();
//---wire up the event handlers---
SigPad.MouseLeftButtonDown += new
MouseButtonEventHandler(SigPad_MouseLeftButtonDown);
SigPad.MouseLeftButtonUp += new
MouseButtonEventHandler(SigPad_MouseLeftButtonUp);
SigPad.MouseMove += new
MouseEventHandler(SigPad_MouseMove);
}
Define the GetSignatureLines()
function so that the coordinates of the signature can be converted from a List object to a string:
//---returns the signature as a series of lines---
private string GetSignatureLines() {
System.Text.StringBuilder sb = new
System.Text.StringBuilder();
//---for each line---
for (int i = 0; i <= _lines.Count - 1; i++) {
//---for each point---
foreach (Point pt in _lines[i]) {
sb.Append(pt.X + ',' + pt.Y + '|');
}
sb.Append('
');
}
return sb.ToString();
}
Code the MouseLeftButtonDown
event handler for the Save button so that the signature can be saved to isolated storage:
//---Save button---
void btnSave_MouseLeftButtonDown(
object sender, MouseButtonEventArgs e) {
//---save into isolated storage---
IsolatedStorageFile isoStore =
IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream =
new IsolatedStorageFileStream('IsoStoreFile.txt',
FileMode.Create, isoStore);
StreamWriter writer = new StreamWriter(isoStream);
//---writes the lines to file---
writer.Write(GetSignatureLines());