Gyrolabs

Random tools to make your life easier

Saving Silverlight Ink

July 19th, 2007 by admin

Recently I was doing a project that required a signature applet. Since silverlight has ink support it was the logical choice. However, after many hours of searching around, I couldn’t seem to figure out how to save the ink without programming in C#. So here’s a solution that can turn the ink from an InkPresenter into XAML and back into ink again.

getStrokesAsString = function(inkpresenter) {
var strokes = inkpresenter.strokes;
var buffer = "<inkpresenter .Strokes>";

for (x = 0; x < strokes.Count; x++) {
buffer += "<Stroke>" +
"<stroke .DrawingAttributes>" +
"<drawingattributes Color='#FF000000' Height='1.75' Width='1.75'/>" +
"</stroke>" +
"<stroke .StylusPoints>";
var curstroke = strokes.getItem(x);
if (curstroke) {
var sps = curstroke.StylusPoints;
for (y = 0; y < sps.Count; y++) {
buffer += "<StylusPoint X='" + sps.getItem(y).X + "' Y='" + sps.getItem(y).Y + "' />";
}
}
buffer += "</stroke>";
buffer += "";
}
buffer += "</inkpresenter>";
return buffer;
}
setStrokesFromString = function(inkpresenter, silverlightobj, strokestring) {
inkpresenter.strokes.Clear();
var allstrokes = "allstrokes";
var allstrokes = silverlightobj.content.createFromXAML(strokestring);
inkpresenter.strokes = allstrokes;
}

Sorry it’t not formatted nicely — wordpress stripped all that out.

Use the getStrokesAsString method to get a XAML string representing all the strokes; just pass it the inkpresenter element.

Use the setStrokesFromString method to transfer a XAML string representing the strokes into actual strokes on the canvas. Pass it the inkpresenter element, the silverlight object (usually window.silverLight), and the XAML stroke string.

Posted in Articles, C#/.NET, Quick Tips | 970 Comments »

Summer Plans

April 15th, 2007 by admin

Posted in Articles | 1807 Comments »

Verizon LG Phone Hack

March 4th, 2007 by admin

Posted in Articles, Quick Tips | 574 Comments »

Downloads Archive

February 25th, 2007 by admin

Posted in New Releases | 65 Comments »

Facebook Apps

February 24th, 2007 by admin

Posted in Uncategorized | 3510 Comments »

Fake Blue Screen of Death

January 10th, 2007 by admin

Posted in New Releases, C#/.NET | 294 Comments »

Internet Connection Monitor v3.1

January 6th, 2007 by admin

Posted in New Releases, C#/.NET | 63 Comments »

Show Empty Cells in IE

January 2nd, 2007 by admin

Posted in Quick Tips | 70 Comments »

Coming Soon

December 11th, 2006 by admin

Posted in Uncategorized | 61 Comments »

Internet Connection Monitor 3.0

November 6th, 2006 by admin

Posted in Uncategorized, New Releases, C#/.NET | 63 Comments »

FilePurge Deleter and Renamer

October 8th, 2006 by admin

Posted in New Releases, C#/.NET | 69 Comments »

JediConcentrate Mod

September 25th, 2006 by admin

Posted in New Releases, Dugg Stories, C#/.NET, Mods | 146 Comments »

SpacerGen v1.1

September 16th, 2006 by admin

Posted in New Releases, PHP | 150 Comments »

Gyrolabs Mobile BETA 1

August 27th, 2006 by admin

Posted in New Releases, PHP | 63 Comments »

SpacerGen

August 22nd, 2006 by admin

Posted in Uncategorized | 65 Comments »

« Previous Entries