Saturday, April 26, 2008

Silverlight Fun

Primarily for the experience, I've been migrating my GDI/command-line based satellite tracking software to a web service and Silverlight application. Ultimately, it's nowhere near as useful since it's not going to be able to control your tracking hardware, but it's a fun excercise. Ultimately, the GDI version would go away and be replaced with a WPF version.

You'd think that building a WPF application and Silverlight application might produce a lot of code that is reusable. Ultimately, there is very little that's reusable primarily due to the constraints that MS put on Silverlight's library and what is available. They removed seemingly random features from Silverlight that, if you were writing a rich application in WPF, you would no doubt use. This means that, at this point, Silverlight is sufficiently handicapped to make code migration between WPF and Silverlight almost pointless. Below are some particular problems I've run across...

Viewport: There is no viewport in Silverlight. The viewport manages auto-sizing, zooming, and scrolling a canvas. This would be ideal for a map application such as the satellite tracker where you sometimes would like to display only a portion of the world view. Unfortunately it doesn't exist and all such presentation magic needs to be handled manually using Transforms on the canvas in question.

Mouse and Keyboard Events: Wouldn't it be nice to be able to tell if the shift key were pressed when a left-click even is caught? Wouldn't it be nice to tell if a right click event happened? The simple things in life are the most important! Really, I'm having to watch shift-key up and down events, toggling a state variable, and checking that variable when a left mousedown even occurs. This is even more complicated by the fact that there's no right-click! so I'm watching various combinations of ctrl-alt-shift keypresses during the mouse events. WHY?

Image Sizes: For some reason, I can't download an image larger than 3000 pixels wide. I'm sure the exact width isn't the true issue, but my world map needs to be 6000 pixels at 5x zoom factor, and it just isn't happening. I'm not sure why, but it's really irritating. [UPDATE 4/26] It looks like this was a problem with Firefox. The images wouldn't load directly in the browser either. Seems that restarting it worked. Makes sense since Silverlight, like flash, is running within the context of the browser and obtains all of its external funtionality through the browser.

Font Hinting: I'm all for this new vector-based rendering engine. I don't understand why that removes any requirements for font hinting. We still have to render fonts at sub 10px heights, and with hinting, the FONTS decide how they look best, not some random coder from Redmond. Sure, one day, we'll be dealing with magical 1200dpi screens, but now I'm still working at not much greater than the good ol' 72dpi resolution.

There are a lot of similar complaints on various blogs from various developers. It's very hard to decode which version of the runtime and development environment people are talking about when they make these complaints. Some features were around in 1.1 which have dissapeared in 2.0, and visa versa. Some people are complaining that some feature is broken or not implemented which should have been. I've noticed that in some cases it seems that folks are mistaken  - generally looking for features as they were in WinForms or GDI whereas they've simply been moved (or obfuscated) in WPF/Silverlight.

One such feature in particular is marshalling calls across threads primarily for GUI updates. I've determined that it is possible, but is implemented using each control's Dispatcher property instead of a Control.Invoke() call as was the case in WinForms. Silverlight fully supports spooling up a thread, doing some work, and invoking method calls back on the GUI thread. I was really worried when I read more than one post from folks who hadn't figured that out and were saying it wasn't supported.

You can see the progress of the app here.
#    Comments [0] |
Comments are closed.

-