Category Archives: Development

Lego Mindstorms NXT 2.0

Unlike Andrew Coates I have a legitimate reason for buying a Lego Mindstorms NXT 2.0 Robotics kit. I have a young son who’s very keen on Lego and has been building his own robots out of cardboard and Sellotape for the last three months.

I must admit that I had expected to be building and programming the first few robots myself whilst my son got the hang of it all. However, that was not the case.

Here’s the robot that is currently built with our kit.


Not very impressive I hear you say? Well take the following into consideration:

  1. It was built in just over 1 hour with no instructions – including the programming

  2. It can crawl quite effectively – moving forward and backward with no wheels

  3. It is programmed to stop when it nears a wall (using Ultrasonic sensor)

  4. It has two touch sensors that operate the linked fan as programmed with two speed settings

  5. I wasn’t involved at all

It is a real testament to the Mindstorms kit that a child who has yet to learn multiplication at school (several years under the kits “official” minimum age) could put all this together himself. The bundled software for programming the robot really is that easy to use.

My only involvement was to write a simple Window Mobile application that could be used to control the robot. This is done via an exposed Direct Command API supported by the NXT 2.0 block’s Bluetooth interface.

This kit is already a winner in our house. There’s even a good blog for it here.

Developing for Windows Mobile – XAML for Win Forms

Many years ago (2004/5?) I was given the task of writing a XAML engine for System.Windows.Forms. It was a great experience and to do the job properly (I hope) it took quite some time. It had support for most of what’s available in WPF’s XAML – namespaces, markup extensions, attached properites (IExtenderProviders in WinForms speak), type converters, late bound binding, styles, triggers etc. plus a bunch of stuff that isn’t – #include, using parameterized constructors, simplified referencing etc.

In my Windows Mobile UI Framework the idea of having the capability of defining screens in XAML was kind of an afterthought. I had truly forgotten how painful it is to define UI’s programmatically. I’ve also never been a fan of form designers – I think they are slow, in-accurate and generate hard to maintain code/XAML. To this day I do 90% of my XAML using an XML editor (VS or Kaxaml).

So as per my last post I whipped up a very simplified XAML parser/renderer to use with my Mobile UI Framework. However, the latest control that I added to the framework was FormHost which allows a System.Windows.Forms control to be hosted within a DrawingElement (my UI base class). Of course when I say “hosted” the FormHost is really just acting as a placeholder so that the hosted control can be positioned during the render pass.

Here’s the code I had to add for FormHost:

using System;
using System.Drawing;
using System.Windows.Forms;
using Spencen.Mobile.UI.Primitives;
namespace Spencen.Mobile.UI.Controls
public class FormHost : DrawingContainer
private Control _hostControl;
public FormHost( IDrawingHost host ) : base( host )
_hostControl = host as Control;
if ( _hostControl == null )
throw new ArgumentException(
"FormHost must have an IDrawingHost that is a Windows.Forms.Control.", "host");
// By default we have no background or border Background = new SolidBrush( Color.Transparent ); Stroke = null; } public Control HostedControl { get; set; } public override bool SupportsRotation { get { return false; } } protected override void OnRender( GraphicsContext context ) { base.OnRender( context ); var transformedBounds = TransformedBounds( context ); if ( !_hostControl.Controls.Contains( HostedControl ) ) _hostControl.Controls.Add( HostedControl ); var newLocation = new Point( transformedBounds.Left, transformedBounds.Top ); if ( newLocation != HostedControl.Location ) HostedControl.Location = newLocation; var newSize = new Size( transformedBounds.Width + 1, transformedBounds.Height + 1); if ( newSize != HostedControl.Size ) HostedControl.Size = newSize; } } }

So pretty simple – but what was extra nice was the fact that it meant I could immediately declare my hosted System.Windows.Forms controls using XAML without any changes to the XAML parser/renderer at all.

<?xml version="1.0" encoding="utf-8" ?>

<DrawingPanel x:Name="container" DesiredSize="Unbound" Background="{null}">
<TextElement Text="Text" DesiredSize="150,60" AutoSize="True"/> 
<RectangleElement DesiredSize="50,80"/>
    <EllipseElement DesiredSize="40,70"/>
<RegularPolygonElement NumberOfSides="6" DesiredSize="80,80"/>
<RegularPolygonElement NumberOfSides="3" DesiredSize="90,70"/>
<RegularPolygonElement NumberOfSides="8" DesiredSize="80,80"/> <Star NumberOfPoints="5" DesiredSize="80,80"/> <!-- Just to spice things up - here's some WinForms controls - just don't expect them to rotate! --> <FormHost DesiredSize="240,40"> <FormHost.HostedControl> <WinForms:TextBox Text="Hello WinForms" Multiline="True" BackColor="240,255,240"/> </FormHost.HostedControl> </FormHost> <FormHost DesiredSize="240,80"> <FormHost.HostedControl> <WinFormsanel> <WinFormsanel.Controls> <WinForms:RadioButton Checked="True" Text="Is WinForms?" BackColor="255,255,223"
Dock="Top" Height="20"
/> <WinForms:RadioButton Checked="True" Text="Is MobileUI?" BackColor="255,255,223"
/> </WinFormsanel.Controls> </WinFormsanel> </FormHost.HostedControl> </FormHost> </DrawingPanel> </View>

MobileUI_Screenshot 5

Developing for Windows Mobile – Mobile XAML?

I’ve now included a “first cut” XAML parser (ultra simplistic) within v0.2 of my Mobile UI Framework.

Allows me to convert:

<?xml version="1.0" encoding="utf-8" ?>
<GradientRectangleElement DesiredSize="Unbound" StartColor="240,240,240" EndColor="200,80,0"/>
<TextElement DesiredSize="400,500" Foreground="200,200,200" Text="Demo" Angle="315" AutoSize="True" 
HorizontalAlignment="Center" VerticalAlignment="Center"
/> <DrawingPanel DesiredSize="Unbound" Background="{null}"> <DrawingPanel.LayoutEngine> <StackLayout Margin="8,4" Padding="4"/> </DrawingPanel.LayoutEngine> <ButtonBar Text="Animations" SecondaryText="Animate properties of graph primitives"
DesiredSize="UnboundAxis, 80" Background="{null}"
/> <ButtonBar Text="Trasitions" SecondaryText="Optimized bitmap animations"
DesiredSize="UnboundAxis, 80" Background="{null}"
/> <ButtonBar Text="Primitives" SecondaryText="Polygon, Ellipse, Image, Text"
DesiredSize="UnboundAxis, 80" Background="{null}"
/> <ButtonBar Text="Behaviours" SecondaryText="Drag with slide"
DesiredSize="UnboundAxis, 80" Background="{null}" Command="{Binding DragDemoCommand}"
/> <ButtonBar Text="Layout" SecondaryText="Stack, Wrap and Radial"
DesiredSize="UnboundAxis, 80" Background="{null}" Command="{Binding LayoutDemoCommand}"
/> </DrawingPanel> </DrawingPanel>


I was getting really sick of doing it the “old fashioned way”

So far I support simple value type converters (float, bool), pen and brush converters, size and padding converters, resource naming (x:Name), complex properties (DrawingPanel.LayoutEngine) and loading types from other CLR namespaces via XML namespace (xmlns:sysDrawing).

Developing for Windows Mobile – Guru Meditation

I’ve been working away for a few nights now trying to put together a simple framework for building user interfaces on a Windows Mobile device. It’s only taken a few nights to build something that I’m pretty happy with… and I was thinking of maybe even posting some source code.

It was at this moment of course that I had a visit from my Inner Guru. You know the one… that little voice in your head that sniggers impolitely whenever you struggle to convert a loop into a LINQ expression. Or when you’re hacking out some prototype code and you need to new up an instance. You know that really its going to need an IOC container, you look around, no-ones watching… in goes the explicit “new Foo()”. Immediately your Inner Guru can be heard muttering to themselves, “tut… tut.. will he never learn…”.

Anyhow, my Inner Guru popped in for a visit just the other day and we had a quick chat about the work I’d been doing on my mobile framework. The conversation went something like this:

Me: Hey – check out this framework I’ve been building for Windows Mobile – pretty cool huh?

Guru: Hmm… yes it appears you’ve made quite some progress.

Me: Yeah – look it can do animations.

Guru: Very impressive. Did you have trouble using the DirectX libraries?

Me: Ah well, err no it’s just using GDI.

Guru: Ah, I see. Does that give you full hardware acceleration on the device?

Me: Um… no I don’t think so.

Guru: Ah, I see. Commendable that you have support for an opacity on each element.

Me: Yeah, well I mean no. It seemed like a good idea at the time but I haven’t done that yet.

Guru: Ah, I see. It appears all objects support using a RotateTransform?

Me: Yeah, well I mean no. I couldn’t figure out how to rotate images an arbitrary amount with decent performance.

Guru: Ah, I see. I notice that your transforms all inherit from a base class which of course must perform the Matrix calculations.

Me: Yeah, well actually no. I mean there is a base class but I haven’t bothered implementing the transforms using Matrix math – they’re just, you-know, hard coded.

Guru: Ah, I see. It seems you’ve done some work building the framework for a layout engine that can be plugged into any container control. Seems a bit WinForms’ish to me, not very WPF like.

Me: Well I didn’t think it was so bad, although I haven’t actually written that bit yet.

Guru: Ah, I see. So no actual layout panels yet, not even the most simple stack panel?

Me: Err, well no – but it wouldn’t be hard to add.

Guru: But you haven’t done it – even though it wouldn’t be hard.

Me: Well no.

Guru: Hmm.

Me: I was thinking of posting the source code.

Guru: I see. So despite the obvious architectural flaws, the missing classes, the lacklustre performance, the questionable code formatting you feel it adequate for public viewing, or perhaps that may be ridicule? I see you’re still using foreach loops – can’t quite seem to wrap your head around LINQ can you dear boy?

Me: Umm…

Fortunately it was at this point that my Inner Guru hit an untrapped exception deep in his runtime. The following image began blinking away in my head.

I suppressed an evil chuckle and posted the code:

Developing for Windows Mobile – Marketplace Sign-up

Windows Marketplace I’ve decided it would be fun and educational to launch a product through the soon to be released Windows Phone Marketplace. Obviously all the major phone/mobile OS vendors have already beaten Microsoft to market – so you would expect them to have taken some of the learnings from these ventures onboard. In other words – I expect them to do a good job of this – both from a customer and developer perspective.

The following is a summary of my experiences in getting an application into the Marketplace thus far…

Sign-up Process

Microsoft have been very crafty with their Marketplace registration process. Its obviously designed to weed out those individuals who are anything less that desperate to get their product into the app store. If you can answer “no” to two or more of the questions below then I suggest thinking twice before you consider signing-up.

  • Do you enjoy trawling IRS websites to learn about the various US tax forms?
  • Do you enjoy reading about country tax laws and specific treaty clauses?
  • Do you want to know the difference between SSNs and ITINs?
  • Do you have easy access to a non-expired passport else birth certificate plus other government photo id?
  • Do you enjoy filling out paperwork and posting (yes snail-mail) your documents overseas?
  • Do you mind taking a PDF signed by a Microsoft rep, on Microsoft letterhead, modifying it yourself and then sending it off to the IRS as an official sanction for an ITIN? [What is the point of this step?]
  • Are you really expecting to make a killer mobile app that will make this all worthwhile?

[Note: If you are a US taxpayer already then most of this will be irrelevant and the process will be a breeze.]

Of course I answered “no” to all of these but as I stated before I’m writing the whole thing off as an “educational experience”. Nothing worthwhile is meant to be easy… right?

[Note: There is actually a pretty good walkthrough/slideshow of the registration process here.]


If you got through the sign-up process don’t think you’ve beaten them. You now have to create your application icon/logo in a wide variety of resolutions (dpi) and sizes. Then you have to tweak the install process to pick out the right imagery for the particular device its being installed on. When I say tweak – I mean write some C code and inject that into the installer. OK – maybe that’s a little unfair – but go check out some of the following blog posts and their related comments.

As one tongue-in-cheek commenter put it:

“Was there some sort of requirement to do this in the most developer-hostile way possible, or was that just a happy accident?”

Getting Verified

During the sign-up process an email verification is sent out to you by the third-party identity verification company (GeoTrust) that are issuing the code-signing certificates. Make sure you respond to this email immediately because it takes a week or two after that for their poor over-worked web server to send out the next email which actually asks you to provide some credentials.

The good news is that you can supply these credentials back to them via email (unlike the IRS).

The bad news is that their systems are a little flaky and four days later they send your exactly the same email by mistake. Luckily their online chat staff seem to be a little more competent than their computer systems and will tell you to ignore the second email whilst they manually forward your details on to the next verification step.

I’m still waiting on a final outcome…

Submitting Your Application

This is the part of the process that I expected to be more challenging but unfortunately I haven’t gotten this far yet. Submitting your application to the Marketplace and have it pass all the internal testing. There are a number of tools that Microsoft have published which they use internally during the testing process. One such is Hopper – which jumps between your application and others – presumably to detect your applications ability to quickly switch (i.e. for incoming call), to use minimal resources particularly whilst switched out and to be stable over a long (2 hour) period.

One major gotcha with some of the test tools and those supplied with the Windows Mobile SDK is that they only work on 32 bit machines. This is annoying to say the least. They only 32 bit machine I have left is the new HP Netbook which my wife had grown rather fond of.

Well – assuming I every get past the verification process I may post some further thoughts on submission and publication.

Tech-Ed Australia 2009 – Day Two

First – here’s a few blog posts which cover some of the sessions I went to yesterday – but in much more detail. I’d recommend both blogs if you’re not already subscribed.

Windows Mobile Marketplace –

Starting a Small Software Enterprise –

Everyone that attended yesterday’s session on the Windows Mobile Marketplace was also sent an e-mail this afternoon to let us know the information we were given regarding the regional pricing policy was incorrect. The price is actually an additional $10 per region, not $99 which I think it quite acceptable. See Jame’s blog post for details.

DEV310 Make Some Magic! Shake, Flip and Flick Your Application for Windows Mobile 6.5!

This talk began with a brief introduction of marketplace and the Race to Market Challenge. This was then followed by a good discussion around new and emerging phone capabilities which included an interesting video of some folk who have developed a multi-touch resistive screen technology. This means you get multi-touch, pressure sensitivity and fine grain accuracy.

Unfortunately for me a large part of the talk was based around how you can use the great open source sensor API to access hardware specific phone features such as accelerometers and light sensors.Would have been interesting for those that hadn’t seen it before – but otherwise just a run through of the provided demos apps.

There was also a quick demonstration of how easy it is to write your own gesture recognition engine for pre 6.5 phones. Simple but very effective.

DEV350 What is new in VS2010 & .NET FX 4.0… and what should you be using in your next project?

The session speaker was Adam Cogan. I tried to listen to him… I really did. But he’s just so annoying!

He spends all his time going off on irrelevant tangents or trying to amuse the audience. Then creeps through the content at a snails pace [hmm… can snails creep?]. His endless audience questions quickly become tiresome too. What makes it even more annoying is that he’s always getting/picking great topics for Tech-Ed sessions. Its just that the delivery is so poor. But then its probably just me. I I always give him a 1 on the review and if everybody else did the same he wouldn’t get the gigs right? Guess I’ll just notch it down to a personality clash – just hoping next year that he decides to do a talk on something less interesting.

I didn’t manage to sit through this talk to the end. A good coffee was much more enjoyable.

DEV320 Visual Studio 2008 IDE Tips

I thought this session would be entertaining though I consider myself fairly familiar with Visual Studio’s IDE (I should be after 7 years) and wasn’t expecting too many surprises. Having said that I came away with at least 5 tips that I certainly intend to apply to my everyday workflow. We didn’t even have to take notes because Sara had posted them just prior to her talk. My favourites were 5, 15 (esp. when used to execute from find combo) and 22. Another great session by Sara.

SQL209 Project Gemini: Self-Service Business Intelligence

This was all new for me. Essentially it seems to be providing business analysis functionality using Excel as the design tool – very much end-user oriented. Support for Excel Services (via SharePoint), using Analysis Services transparently with scheduled updating of data sources. The demo was very well delivered I was impressed in how the convergence of Excel, SharePoint, Silverlight, Reporting Services and Analysis Services worked seamlessly to produce the output.

To top it off the presenter showed how the project Gemini Excel add-in could sort and filter 101 million rows in real time (sub-second) even when running on a HP Mini netbook. All via an in-memory data engine and clever use of compression.

Its being delivered as part of SQL 2008 R2 together with Office 2010.

Tech-Ed Australia 2009

IMAG0042 I’m at Tech-Ed again this year (that’s three in a row!). Unfortunately this year I had to pay for the privilege since neither the company I’m currently working for nor Microsoft came to the party. Being an independent contractor I hardly expected my client to foot the bill – but I did try and get a ticket off of Microsoft – after all they footed the bill last year.

Day One of the main event has just finished and I was generally very impressed with the sessions I attended. I don’t really expect to learn a great deal at Tech-Ed. I figure its geared mainly towards corporate developers/IT pros who don’t necessarily have the passion/inclination to keep right up with emerging technologies and processes outside of company time. So if I don’t come to Tech-Ed to learn about the future of WPF, MVVM trends, ORMS and MEF then what am I doing here?

Well – to answer that he’s a quick recount of the sessions I attended today.


Pretty much on target this year. Some opening spiel about how now is a good time to be innovating which was further enforced by a HP representative. Then into some demos – Office 2010, a glimpse at VS 2010 CodePlex and Blend 3 and some Windows 7.

SOA303 A Lap around Microsoft Code Name "Oslo"

This Oslo thing has got to go somewhere… eventually… right? The presenter certainly did the best job I’ve heard yet of describing Oslo with demos of M, Quadrant and Intellipad. The talk was done well, the demos flawless but i still came away wondering whether this is really going to mature into a product that will be accepted in the real world.

DEV230 A Tour of CodePlex

I was one of the many that joined the petition to get Sara Ford to come down to Oz. I’m a relatively new subscriber to Sara’s blog – having caught the end of her VS 2008 tips and then her musings and tips for her new role as Codeplex PM.

She seemed a little nervous in her part of the Keynote (looking up at 2500+ strangers) but in this session she was on fire. Its always a little awkward watching how the US speakers react to the subdued Australian audiences – but Sara didn’t miss a beat – she just steam-rolled ahead with a level of enthusiasm that was truly contagious.


In fact – so inspired I’m going to post my latest project (Windows Mobile stuff) on Codeplex.

ARC203 How to build a small software enterprise from zero

I picked this session at the very last minute and as it turns out that was a choice very well made.

The speaker was a Perth based book author ( {yawn} – so who isn’t) by the name of Joseph Albahari. But then I discover he also happens to be the author of Linqpad (automatically elevating him to Legend status)! Just last week I was considering upgrading his most excellent utility to the premium version that includes intellisense auto-completion.

This talk was full of practical advice on how to make your own business out of developing software, with plenty of good examples from Joseph’s own journey with Linqpad. The slides, delivery and content in this talk were all first class.

WEB303 Free up the UX Bottleneck

This session was an overview of Sketchflow (within Expression Blend 3) by Shane Morris. Of all the sessions I attended today this one was the least rewarding. That was through no fault of Shane’s who covered the topic well – simply that I was already to familiar with the content. Particularly considering I’d seen Matt Morphet’s similar (dare I say superior) presentation at Remix and since then had a chance to play quite a bit with Sketchflow myself. Bad choice on my behalf – but then there wasn’t any other compelling content in this timeslot.

DEV260 Distributing and Monetizing Windows Mobile Applications through the Windows Marketplace for Mobile

I’ve been messing around building a few simple apps for my new HTC Touch Diamond 2 device and have considered launching an app or two on Microsoft’s new Windows Mobile Marketplace. I’d even gone so far as to entering a couple of very simple entries into the Codemason’s competition.

This talk became a very frank discussion about the good and bad points of the new Marketplace. It was definitely worth going to and the speaker was very open about the shortfalls in the scheme. For instance, although the marketplace will allow apps to be delivered to any of 29 countries you have to target each country individually – effectively taking a US$99 hit for registering each application instance in each country. Seems to make sense to initially target any application for the US only – I can’t see Australia or New Zealand having the volume of Windows Mobile users to support anything but a very locale specific application.

I got the general impression that most people leaving this talk would be less inclined to launch applications via Windows Mobile Marketplace. Seems a shame – like Microsoft almost got it right but then the marketing team came along at the last moment and crippled their solution.

Some random negatives:

  • Seriously – invest in a schedule builder that works. Please! How hard can this really be? Every year they insist on having some terrible web interface that has an awful user experience. It takes forever to get things into your schedule. This year is the worst yet. Its truly appalling – it doesn’t seem to work at all. Doesn’t matter how many times you click add/remove the schedule just won’t update. Most annoying!
  • With so many delegates with mobile devices Telstra’s NextG network seems a little saturated. It’s been a bit hit and miss and early in the evening I’ve been getting some really poor throughput.

And the flip side:

  • All delegates at Tech-Ed Australia 2009 receive a HP Mini 2140.
  • Mine was scheduled to be given to my mother-in-law as a lame-ass cheapo computer that will let her surf the net. The more time I spend with it though the more I’m starting to like it. The build finish is really very nice, performance seems not as bad as I expected and it seems to run Windows 7 Ultimate very nicely. The only thing about the device that is anything other than sweet is that it seems very loud. In a quiet hotel room my Fujitsu tablet PC can’t be heard at all over the HP Mini’s constant whirring even though its not in use.
  • Wireless connectivity at the event has been very good so far. After a few initial attempts at getting a connection the HP Mini worked flawlessly with the wireless. Resuming from sleep it connects back to the network in a matter of seconds. Good job!
  • Weather is awesome.
  • Got a good room at Jupiter’s Casino which is connected to the venue by a walkway.

Phew – that post was a little longer than I had originally intended. Anyone who has read this far is probably a work colleague – and yes I’m about to order room service then connect via VPN and start working on those bugs.

Developing for Windows Mobile – Composing User Controls

Tonight I finished refactoring the mobile UI framework I’ve been putting together so that it can correctly handle composite elements. Previously I’d been able to handle a collection of polygons (Rectangles, Stars etc.). I’ve now introduced the concept of DrawingContainers that themselves have a collection of elements, any of which may be another DrawingContainer.

The idea is that I can now construct UI controls that themselves are composed of simple graphic primitives. Just like WPF right? Each graphic element can have its own animations and hit test capabilities and controls can be composed within each other to form richer user controls. All this is rendered to the hosting Windows.Forms.Control in a single double-buffered render.

The class diagram below gives an indication of where I’m currently at. Everything in the diagram has been implemented.



As one example of compositing controls I used a multi-part windmill.

Windows Mobile Spinning Wheel Thing_Thumb

Defined in code as:

var center = new Point( hostCanvas.Width / 2, hostCanvas.Height / 2 );
var yellowBrush = new SolidBrush( Color.Yellow );
var panel = new Panel( hostCanvas ) { Size = hostCanvas.Size, Center = center };
var bar1 = new Panel( hostCanvas ) { Size = new Size( 200, 20 ), Center = new Point( center.X, center.Y - 190 ) };
var bar2 = new Panel( hostCanvas ) { Size = new Size( 200, 20 ), Center = new Point( center.X, center.Y + 190 ) };
panel.Children.Add( new Rectangle() { Size = new Size( 50, 400 ), Center = center } );
bar1.Children.Add( new Rectangle() { Size = bar1.Size, Position = new Point( 0, 0 ) } );
bar2.Children.Add( new Rectangle() { Size = bar1.Size, Position = new Point( 0, 0 ) } );
bar1.Children.Add( new Star() { Size = new Size( 75, 75 ), 
Center = new Point( bar1.Size.Width / 2 - 90, bar1.Size.Height / 2 ),
Background = yellowBrush } ); bar1.Children.Add( new Star() { Size = new Size( 75, 75 ),
Center = new Point( bar1.Size.Width / 2 + 90, bar1.Size.Height / 2 ),
Background = yellowBrush } ); bar2.Children.Add( new Star() { Size = new Size( 75, 75 ),
Center = new Point( bar2.Size.Width / 2 - 90, bar2.Size.Height / 2 ),
Background = yellowBrush } ); bar2.Children.Add( new Star() { Size = new Size( 75, 75 ),
Center = new Point( bar2.Size.Width / 2 + 90, bar2.Size.Height / 2 ),
Background = yellowBrush } ); panel.Children.Add( bar1 ); panel.Children.Add( bar2 ); panel.Transforms.Add( _rotateTransform ); _rotateTransform.RenderCenter = new Point( hostCanvas.Width / 2, hostCanvas.Height / 2 ); panel.Host.AnimationManager.AddAnimation(
new FloatAnimation( _rotateTransform, "Angle", new TimeSpan( 0, 0, 50 ) ) { FinalValue = 3600 } ); var barRotation = new RotateTransform(); bar1.Transforms.Add( barRotation ); bar2.Transforms.Add( barRotation ); panel.Host.AnimationManager.AddAnimation(
new FloatAnimation( barRotation, "Angle", new TimeSpan( 0, 0, 50 ) ) { FinalValue = -7200 } ); var starRotation = new RotateTransform(); bar1.Children[ 1 ].Transforms.Add( starRotation ); bar1.Children[ 2 ].Transforms.Add( starRotation ); bar2.Children[ 1 ].Transforms.Add( starRotation ); bar2.Children[ 2 ].Transforms.Add( starRotation ); panel.Host.AnimationManager.AddAnimation(
new FloatAnimation( starRotation, "Angle", new TimeSpan( 0, 0, 50 ) ) { FinalValue = 18000 } ); hostCanvas.View.Children.Add( panel );

Other features so that I’ve got so far:

  • Support for Behaviours. So far the only implementation is a DragBehavior that allows dragging any attached element along one or both axis. Even supports a “flick” by determining the angle and velocity on mouse up and applying an animation with a cubic easing function to simulate velocity decay.
  • Scrolling between views/pages using an easing function (and BitBlt).
  • Simple image support.

Other ideas:

  • Button and ItemsList controls.
  • Stack and custom (e.g. radial) layout panels.
  • Integration with platform APIs to allow drawing of rounded rectangles, gradient fills and to support alphas.
  • A transform for flipping vertically or horizontally.
  • Behaviour to support an ICommand style interface to allowing hooking UI interactions with a view model.

Developing for Windows Mobile – Animation Basics

This post is a follow on from my most recent efforts creating some screens for a Windows Mobile application. I had decided to write a simple graphics library to help me do some nice transition effects. So over the last two nights I ported (actually rewrote) my original WinForms Transition demo to Windows Compact Framework.

So far I have support only for polygons, but that includes hit testing, transforms (rotate, translate, scale), animation (floats, points, colours, brushes) and easing functions (currently sine in/out and elastic out).

Hopefully I’ll post more about this (with source code) soon – but here is a quick demo video that I captured using Expression 3’s new screen capture utility (very neat!).

Windows Mobile Animations_Thumb

So far I’ve been really happy with the performance. Will be interesting to see how much it degrades once I start adding gradients, transparency and more complex shapes. [Note that the video doesn’t really reflect the performance too well.]

Developing for Windows Mobile – Getting Started

Now I have my new Windows Mobile 6.1 device I’ve decided to delve once more into the mysterious realm of developing for mobile devices. My previous forays have both been very lightweight. The most recent was simply displaying bus timetable information within a ListView control. Despite its simplicity its actually something I find very useful on my daily commute – rather than digging around in my bag for the paper version and then tuning in to the times and stops that I’m interested in.

Here’s a screenshot of my original Bus Timetable applet (its just too trivial to be awarded the title “application”):

BusTimetable - PocketPC 2003 SE

Now here’s a screenshot of the same application running on my new HTC device:

2009 07 06_21 15 12_0015_111g

Hmm.. some things scaled and some didn’t But overall when compared to the other default applications (particularly those written by HTC) it looks pretty lame.

So, I decided to get to work and create a user interface that:

  1. Scales well across the more common Windows Mobile devices resolutions (at least 240×320, 480×640 and 480×800).
  2. Fits with the “look and feel” of the pre-installed HTC applications.
  3. Works with touch only – this type of application needs to work using just my thumb since common scenarios for its use are when I’m walking through a crowd and carrying a bag.

With the help of the UIFramework from MSDN I managed to get some screens that I was pretty happy with. The icons and selection had gradient fills and the icons were superimposed on their corresponding “frames” with a transparent background.

2009 07 06_21 27 31_0016_111g  2009 07 06_21 28 35_0018_111g 

However, I soon found that things weren’t quite a rosy as I was hoping. To start with the UIFramework library sample seems to be a “work in progress”. That is to say it has a lot of bugs or parts that simply don’t work – its obviously intended as a starting reference for someone intending to owner draw their own controls/graphic elements.

Also, I originally created each ButtonBar as a user control. As with WinForms this meant that when it came to scrolling the buttons it looked terrible. Really slow – and each button is its own Window hence there is no capability of double-buffering. Man – I have been so spoiled by WPF – I had long forgotten all this pain! This trick then seemed to be to ditch using controls and just render the entire UI on a single user control. That way the main user control can double buffer all the rendering and there is only one render pass. The downside of course is that you then have to take care of everything – drawing all your own controls, hit testing, anchoring, dpi scaling etc.

Well – I’m not sure where I’m going with all this. But I did consider porting my WinForms Transitions code to the Windows CF. Even this was a no-go though – because although it contains plenty of base classes and helper methods for transforming and hit testing objects it relies heavily on using GraphicsContainer to do the actual transforms. These aren’t supported by the Compact Framework. So, I started from scratch, building a simple graphics library that will let me scale, rotate and translate graphic primitives. So far I have a spinning/zoomable rectangle – guess you gotta start somewhere.