Thursday, March 13, 2008

Running WPF on gas pump (or other Windows CE devices)?

What do you think, is it possible to run WPF on Windows CE enabled devices (e.g. gas pumps, GPS systems, robots, game or automatic teller machines or, even, scientific calculators)? Let's see following code:

StackPanel panel = new StackPanel(Orientation.Horizontal);
            Ellipse ellipse = new Ellipse(10, 10);
            ellipse.Fill = new SolidColorBrush(Colors.Red);
            ellipse.Stroke = new Pen(Color.Black);
            Rectangle rect = new Rectangle();
            rect.Width = 40;
            rect.Height = 40;
            Line l = new Line(20, 20);
            Polygon polygon = new Polygon(new int[] { 0, 0, 20, 0, 20, 20, 0, 20 });

            panel.AddHandler(Buttons.ButtonUpEvent, (ButtonEventHandler)delegate
                panel.Orientation = panel.Orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal;
            }, false);

Or even this code

void OnButtonHeld(object o)
    Button b = (Button)o;
    Dispatcher.Invoke(TimeSpan.FromTicks(10), (ButtonHeldDelegate)delegate(Button btn)
        while (Buttons.IsButtonDown(btn))
            switch (btn)
                case Button.Left: p.X--; break;
                case Button.Up: p.Y--; break;
                case Button.Right: p.X++; break;
                case Button.Down: p.Y++; break;
                case Button.Select: p.X = mainWindow.Width / 2; p.Y = mainWindow.Height / 2; break;

    }, b);

void moveMouse()
    host.DrawRectangle(Colors.Black,2,p.X,p.Y, 100, 100,0,0,Colors.Red,0,0,Colors.Blue,100,100,255);

This code will run on any Windows CE device. And it is not WPF :) It's .NET Micro Framework. Actually, when we're looking for it's syntax, it looks like WPF/Silverlight and .NET Micro Framework have the same architect. However, it cannot use hardware acceleration and has very limited number of objects. All this because of it's purpose "platform to devices that do not need the fuller functionality available in the .NET Framework and the .NET Compact Framework". I would add Windows Presentation Foundation as well.

The application model of .NET Micro Framework is very similar to WPF. It has native CLR/PAL and HAL and managed libraries.


Sufficient number of components in CLR - types, threads and timers, reflection, serialization, GC, networking, other connectivities etc., enables you to create, even games, that will run on even Heart Device.

Other words, cool technology and possible cool appliance for your programming skills. 

How to start? First of all, download .NET Micro Framework v2.5 (VS2005, you can also add Microsoft.SPOT assemblies into your regular VS2008 project) and start programming. It's really simple (I build snake game for less, then hour)

See your applications, running on embedded devices. BTW, I'll probably present something, developed with this framework in my TechEd session aside with WPF, Silverlight and XNA... Keep tuned and have a nice day

No comments: