Free Professional Visual Studio 2010 book at Remix Australia 2010

Free Professional Visual Studio 2010 book at Remix Australia 2010


If you’re going to Remix Australia 2010and want a FREE copy of Professional Visual Studio 2010then you need to attend either my session Windows Phone 7: The emperor’s got some new threadsor Chris Anderson’s Silverlight 4session. Chris, also a co-author on the book, and I will both be giving a away 1 copy during each of our sessions.

If you miss out on the free copies and still want a copy, which we both hope you do, then we’ll have a total of 4 books available for sale at $50 a book. This is a discount on what you can purchase it for here in Australia. There are only 4 books available, since we have to lug them down from Sydney, so it will be strictly on a first in basis. We won’t be taking pre-orders so you must find us during Remix (that’s anytime after the keynote has started).

Remix Australia 2010: I’m speaking on Windows Phone 7

Remix Australia 2010: I’m speaking on Windows Phone 7

Speaking_at_remix_au_2010_large Next week is the Australian reincarnation of the sensation MIX event held earlier this year in Vegas. This year remix Australia is being held in Melbourne over not one but two whole days. As you probably know I’m not a “web-guy” so you might be wondering what I’m doing showing up at a web event. Well here’s the catch, it’s all about rich internet-enabled applications. I don’t care if it’s written in HTML 5, Silverlight, WPF or hey, even WinForms, so long as you’re doing intelligent things like client side storage, offline support and rich UI then you’re talking my language.

This year my focus is almost exclusively on Windows Phone 7. My session, entitled Windows Phone 7: The emperor has got some new Threads, showcases the tools and technologies that make up developer story for Windows Phone 7. Immediately following my session is Luke Drumm’s session on Windows Phone 7: Debauchery on the silicon seas : High adventure in a small amount of code. I’m really looking forward to this session to watch Luke smash the Phone around a bit using the XNA Framework.

There is just so many awesome features to discuss, but here are a few of the points to watch out for in my session.
– Notification Services
– Location
– Emulator Automation
– Accelerometer
– Panoramic and Pivot controls
– Voice synthesis, transcription and translation

All this in a hour! Don’t forget if you like what you see you should pre-order the book I’m working on (yes, another one): Professional Windows Phone 7 Application Development: Building Windows Phone Applications Using Silverlight. The title on Amazon is a little misleading at the moment as it won’t be covering much on games development or XNA (one chapter on this) but it is a deep dive on everything that makes building Windows Phone applications in Silverlight so great.

What to do with an audio recording using the microphone on Windows Phone 7?

What to do with an audio recording using the microphone on Windows Phone 7?

Most of the examples that you see for working with the microphone on Windows Phone 7 usually take the resulting byte array and either play it back (using the XNA audio namespace) or save it in its current form to IsolatedStorage. Unfortunately, the byte array isn’t much use by itself as it can’t be played back directly using say Media player. What you need to do is actually convert it to a wav file by wrapping the raw sample data in the appropriate header information. Following the WAV specifications you end up with a set of helper methods that look similar to the following:

using System;
using System.Text;

namespace MediaHelper
    public static class SoundUtilities
        public class WaveFormat
            public int Encoding { get; set; }
            public int AverageBytesPerSecond { get; set; }
            public int BlockAlign { get; set; }
            public int Channels { get; set; }
            public int SamplesPerSecond { get; set; }

        public static byte[] ConvertRawSamplesToWav(
           byte[] samples, WaveFormat format)
            var ascii = Encoding.UTF8;
            var byteArrayLength = 36 + samples.Length;
            var byteArray = new byte[byteArrayLength+10];
            var index = 0;

            // Specify that this is a RIFF file and the length of the file in bytes
            index += byteArray.CopyInto(index, ascii.GetBytes("RIFF"));
            index += byteArray.CopyInto(index, byteArrayLength.AsFixedByteArray(4));

            // Specify that this is a WAVE and start the format header
            index += byteArray.CopyInto(index, ascii.GetBytes("WAVE"));
            index += byteArray.CopyInto(index, ascii.GetBytes("fmt "));

            // Format header is fixed size of 16
            index += byteArray.CopyInto(index, (16).AsFixedByteArray(4));

            // Encoding: "1" for PCM
            index += byteArray.CopyInto(index, (format.Encoding).AsFixedByteArray(2));

            // Number of Channel
            index += byteArray.CopyInto(index, (format.Channels).AsFixedByteArray(2));

            // Samples per second
            index += byteArray.CopyInto(index, (format.SamplesPerSecond).AsFixedByteArray(4));

            // Average bytes per second
            index += byteArray.CopyInto(index, (format.AverageBytesPerSecond).AsFixedByteArray(4));

            // Block Align
            index += byteArray.CopyInto(index, (format.BlockAlign).AsFixedByteArray(2));

            // Bits per sample
            index += byteArray.CopyInto(index, ((8*format.AverageBytesPerSecond)/format.SamplesPerSecond).AsFixedByteArray(2));

            // The Samples themselves
            index += byteArray.CopyInto(index, ascii.GetBytes("data"));
            index += byteArray.CopyInto(index, samples.Length.AsFixedByteArray(4));
            index += byteArray.CopyInto(index, samples);

            return byteArray;


        public static int CopyInto(this byte[] byteArray, int offset,byte[] bytes )
            bytes.CopyTo(byteArray, offset);
            return bytes.Length;

        public static byte[] AsFixedByteArray(this int number, int fixedByteArraySize)
            int remainder, result;
            var returnarray = new byte[fixedByteArraySize];
            result = DivRem(number, 256, out remainder);

            if (result >= 1)
                returnarray[0] = Convert.ToByte(remainder);
                var tmpArray = result.AsFixedByteArray(fixedByteArraySize - 1);
                tmpArray.CopyTo(returnarray, 1);
                returnarray[0] = Convert.ToByte(number);
            return returnarray;

        public static int DivRem(int a, int b, out int result)
            result = a % b;
            return (a / b);

Of course, in order to make use of this code you need to know what the format of the raw samples are. This can be obtained by looking at the Microphone instance that you are using to record the audio. The following screenshot illustrates the various properties you will need to know


Windows Phone 7 Emulator Themes and Resources

Windows Phone 7 Emulator Themes and Resources

If you’ve been looking at building Windows Phone 7 applications using Silverlight you will probably have come across the set of styles and resources that are defined within the App.xaml file. For example the following section defines the foreground and background colors to be used.

    <!--RootFrame points to and loads the first page of your application-->
        <phoneNavigation:PhoneApplicationFrame x_Name="RootFrame" Source="/MainPage.xaml"/>

    <!-- Resources for following the Windows Phone design guidelines -->
        <!--************ THEME RESOURCES ************-->
        <!-- Color Resources -->
        <Color x_Key="PhoneBackgroundColor">#FF1F1F1F</Color>
        <Color x_Key="PhoneContrastForegroundColor">Black</Color>
        <Color x_Key="PhoneForegroundColor">White</Color>
        <Color x_Key="PhoneInactiveColor">#FF666666</Color>
        <Color x_Key="PhoneDisabledColor">#FF808080</Color>
        <Color x_Key="PhoneSubtleColor">#FF999999</Color>
        <Color x_Key="PhoneContrastBackgroundColor">#FFFFFFFF</Color>
        <Color x_Key="PhoneTextBoxColor">#FFBFBFBF</Color>
        <Color x_Key="PhoneBorderColor">#FFCCCCCC</Color>
        <Color x_Key="PhoneTextSelectionColor">Black</Color>
        <Color x_Key="PhoneAccentColor">#FF1BA1E2</Color>

One thing to note here is that if you change the theme background or accent (see image below: Start –> Settings, Theme) this will NOT be reflected by your application the next time your run it. This is because the colors have been hard coded in the App.xaml file


The solution to this is to remove the appropriate resources from the app.xaml file. Of course, this will break your designer experience within Visual Studio and Blend but will mean that your application reflects the theme settings of the emulator. But here lies the problem, which resources do you remove? Well of course, you can remove all the resources that are going to be defined by Windows Phone…. ok, but how do we know what they are?

Justin has been releasing a number of awesome posts on connecting to the emulator using the managed wrapper. In particular the article on Emulator Automation is definitely worth studying closely. Using the hacked emulator image I went trawling through the Windows directory and notices a number of xaml files that looked interesting. Using Justin’s post as a starting point I decided to rip a couple of these xaml files off the emulator and take a look at what’s inside. The process for doing this is relatively straight forward:

– Create a Windows application (WinForms or WPF, doesn’t matter)

– Add references to c:Program FilesCommon Filesmicrosoft sharedPhone ToolsCoreCon10.0BinMicrosoft.Smartdevice.Connectivity.dll

– Write some code to receive the files you want from the emulator

// Get CoreCon WP7 SDK
DatastoreManager dsmgrObj = new DatastoreManager(1033);

Platform WP7SDK = dsmgrObj.GetPlatforms().Single(p => p.Name == "New Windows Mobile 7 SDK");

// Get Emulator / Device
bool useEmulator = true;
Device WP7Device = null;
if (useEmulator)
    WP7Device = WP7SDK.GetDevices().Single(d => d.Name == "Windows Phone 7 Emulator");
    WP7Device = WP7SDK.GetDevices().Single(d => d.Name == "Windows Phone 7 Device");

// Connect to WP7 Emulator / Device

    ICcConnection phone = WP7Device.GetType().GetField("mConmanServer", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(WP7Device) as ICcConnection;

    f.ReceiveFile(@"", @"", true);
    f.ReceiveFile(@"windows000_themeresources.xaml", @"c:temp000_themeresources.xaml", true);

catch (Exception ex){

When you execute this code (you need to have the Windows Phone 7 emulator already running) it will download the two files and 0000_themeresources.xaml to the c:temp directory. You can then open them up and inspect which resources are defined. For example the themeresources.xaml file starts as follows:


  <Color x_Key="PhoneBackgroundColor">White</Color>
<Color x_Key="PhoneContrastForegroundColor">White</Color>
<Color x_Key="PhoneForegroundColor">Black</Color>
<Color x_Key="PhoneInactiveColor">#ffcccccc</Color>
<Color x_Key="PhoneDisabledColor">#ffcccccc</Color>
<Color x_Key="PhoneSubtleColor">#ff999999</Color>
<Color x_Key="PhoneContrastBackgroundColor">Black</Color>
<Color x_Key="PhoneTextBoxColor">#ffbfbfbf</Color>
<Color x_Key="PhoneBorderColor">#ff999999</Color>
<Color x_Key="PhoneTextSelectionColor">White</Color>
<Color x_Key="PhoneAccentColor">#FF339933</Color>

If you look at the windows directory on the emulator (using the hacked emulator you can used the shortcuts application but you need to select Options-> Show All Files) you will see that there are and themeresources.xaml files numbered 0000, 0001, 0002 and 0003, and then also 0100, 0101, 0102 and 0103. As you can guess these correspond to the eight themes (light/dark with orange/blue/red/green). You can download all of these xaml files and take a look at the resources that are defined.

Disclaimer: Don’t make any dependencies on the values of these resources as they could/might/probably will vary before Windows Phone ships.

Windows Phone 7 Emulator Launch Time versus Notification Services

Windows Phone 7 Emulator Launch Time versus Notification Services

I’ve got a bit of a dilemma as to which emulator image to work with for Windows Phone 7.  As you are no doubt aware there is a hacked emulator image available that opens up some of the hidden functionality of Windows Phone 7. For example most of the built in applications such as the hubs and Office are available in the hacked build.

Here’s a couple of things you might not know:

– The official build is SLOW and I’m not talking slow whilst running applications (I think this is about the same speed), I’m talking about the boot and time to launch/connect debugger to your application. This is a royal pain and has caused me to go back to the hacked build because it’s so much quicker to debug your application on.

– The hacked build will NOT work with Notification services. If you are seeing any issues with notification services, make sure that you a) use the official build and b) make sure you check your proxy settings. Even if you think your proxy settings won’t make a difference, try turning them off and seeing whether notification services work.

Here’s the dilemma – I want to use notification services in my application but I don’t want to have to wait up to 5 minutes for Visual Studio to launch and debug my application……

Windows Phone Hacked Emulator Not Working With Notification Services

Windows Phone Hacked Emulator Not Working With Notification Services

For the last week I’ve been trying to work out why my sample application for the Windows Phone Notification API had stopped working. And yes, before everyone chimes in with “have you set the publisher” and “have you updated the capabilities list” I’d already done all that and had fully working samples showing tile, toast and raw notifications. About a week ago all these samples stopped working. Thinking I must have done something wrong I tried all the available samples on the web that I could find. None of them worked either – the symptom is that you never get a Channel Uri back, if you locate and existing channel it’s uri is always null.

The fix was….. switch back to the official emulator image. That’s right, I’d been using the hacked emulator ROM image (the one that was released based on the April emulator). Turns out there must be something screwy going on because the notification services seem to have stopped playing nice with it. I switched back to the official emulator image and everything works again. Ho Hum… I wonder if that was intentional by Microsoft, or just a result of them tightening security around the notification services.

Customising the Visual Studio 2010 Start Page

Customising the Visual Studio 2010 Start Page

I just posted an update on how you can customise the Visual Studio 2010 start page. The guidance from MSDN requires you to a) have the Visual Studio SDK installed and b) download a project template that was designed for the RC. To be honest I don’t think that’s a great way to highlight how easy it is to customise the start page.

Anyhow, the full details are across on the Professional Visual Studio 2010 website. Don’t forget to grab yourself a copy of the book via the link to Amazon

Windows Phone 7 Flicker Viewer

Windows Phone 7 Flicker Viewer

Firstly, I need to point out that Dave Glover was the original person to put together the code for this example Windows Phone 7 application. I just tidied it up and did the screencast (no audio).

This was actually delivered (with audio) yesterday during the webdu keynote. I figured it would be worth doing a quick screencast of it this morning and making it available for anyone interested.

Windows Phone 7 – Photo Extras Application Extensibility

Windows Phone 7 – Photo Extras Application Extensibility

One of the things we heard about at MIX was the ability for you to register your application as a photo editing application. A registered application would appear in the Extras list when viewing a photo on the device, allowing the user to launch a third party application to edit, modify, manipulate a photo. The documentation released at MIX provided the necessary instructions (latest version is here) but it wasn’t until the April update to the WP7 developer tools that it was actually possible to see this in action.

The steps are super simple:

1) Create a new xml file in the root of your Windows Phone 7 project called Extras.xml (don’t worry about changing any of the build properties).

2) Change the contents to the following:

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


3) Build and run your application. Your application will now appear in the Extras list.

Ok, but how do I see it in action. Well the easiest way is actually to use the unlocked emulator image. You can then just open the Pictures hub and look at any of the sample images. Expand the Application Bar (somewhat hidden but if you click the image you’ll see it appear) and then select extras.

image image

I can’t seem to work out how you then access the image that’s been selected from within your application but it’s either something I haven’t found yet, or not in this build yet.