coderox

The console app of Windows Phone

Tags: Windows Phone

Yesterday I decided to evaluate how far I could go in creating a minimal application in Windows Phone, my goal was the following:

  1. As few lines of code as possible
  2. As few lines of configuration as possible
  3. As few files as possible
  4. As few references as possible
  5. The smallest XAP-size possible

The result is quite interesting and here is a short description of the end result.

I ended up with a project with only three files:

  • WMAppManifest.xml
  • App.cs
  • ApplicationIcon.png
<?xml version="1.0" 
      encoding="utf-8"?>
<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" 
            AppPlatformVersion="7.1">
  <App xmlns="" 
       ProductID="{30c53039-eda6-4897-898f-0274e8914fe7}" 
       Title="PhoneApp1" 
       RuntimeType="Silverlight" 
       Version="1.0.0.0" 
       Genre="apps.normal" 
       Author="PhoneApp1 author" 
       Description="Sample description" 
       Publisher="PhoneApp1">
    <IconPath>ApplicationIcon.png</IconPath>
    <Capabilities/>
    <Tasks>
      <DefaultTask Name="_default" />
    </Tasks>
    <Tokens>
      <PrimaryToken TokenID="PhoneApp1Token" 
                    TaskName="_default">
        <TemplateType5>
          <BackgroundImageURI>ApplicationIcon.png</BackgroundImageURI>
          <Count>0</Count>
          <Title>PhoneApp1</Title>
        </TemplateType5>
      </PrimaryToken>
    </Tokens>
  </App>
</Deployment>

The code above is the entire WMAppManifest.xml. I've removed as much I think is possible.

using System.Windows;
using System.Windows.Controls;
using Microsoft.Phone.Controls;

namespace PhoneApp1
{
    public class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            var grid = new Grid();
            grid.Children.Add(new TextBlock { Text = "hello world" });
            Content = grid;
        }
    }

    public class App : Application
    {
        public App()
        {
            var frame = new PhoneApplicationFrame();
            frame.Content = new MainPage();
            RootVisual = frame;
        }
    }
}

And here is all of the code for the application. I've removed all XAML-code and use "code-behind" for all creation. The ApplicationIcon.png file is a simple 1x1 pixel image which is used both for application icon and tile-background. The end result became:

  1. As few lines of code as possible - 27 lines (including some empty lines and line breaks  for readability)
  2. As few lines of configuration as possible - 30 lines (having all attributes and elements on separate lines, 19 if I keep attributes on same line as beginning element)
  3. As few files as possible - 3 files
  4. As few references as possible - 5 references ( Microsoft.Phone, mscorlib, system, System.Core, System.Windows)
  5. The smallest XAP-size possible - 2,74 kb

1 comment on “The console app of Windows Phone”

Add a Comment