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 | 1125 Comments »

Verizon LG Phone Hack

March 4th, 2007 by admin

This has been around for awhile and a lot of people know about it, but heres a little trick to confuse your friends. This ONLY works on VERIZON LG PHONES.

  1. Go into the phone’s menu
  2. Type 0 (zero) seven times
  3. Hit #
  4. Go to ‘Motor Test’
  5. Turn it on

Then the phone will vibrate until you go back in and turn it off.

Posted in Articles, Quick Tips | 604 Comments »

Show Empty Cells in IE

January 2nd, 2007 by admin

IE doesn’t show table cells if they are empty, which can cause a lot of problems. The most obvious fix is to just put <td>&nbsp;</td>, but this isn’t a viable solution if you are generating data from a table or if your site is already created. If you are using IE, below is an example of a table that doesn’t show empty cells:

wefaew
oweifj woeifj

As you can see (if you’re using IE), the cells simply don’t show up and it looks extremely ugly. It looks even worse when using special borders. Here is a simple script that will go through all tables on your page and fill the contents of the empty cells with &nbsp;

Put this script in the <head> of your document to show empty cells in IE:

note: the <!–[if lte IE 7]> line allows this script to run only in IE browsers.

<!--[if lte IE 7]>
  <script type="text/javascript">
   window.onload = function() {
        tds = document.all.tags("td");
        for (x = 0; x < tds.length; x++) {
            if (tds[x].innerHTML == '')
                tds[x].innerHTML = "&nbsp;";
        }
   }
   </script>
<![endif]-->

Posted in Quick Tips | 70 Comments »