Integer to string formatted as currency

Since it has been a while since the last post, I thought I would give a quick trick that shows the power of string.Format().

Say you got an integer “price” that you want to display in a string, but formatted as currency. You can do this very easily using string.Format():

int price = 2795000;
string priceStr = string.Format("The price is {0:C}", price);


priceStr would now be “The price is 2.795.000,00 kr” if the Culture was set to Swedish. If you want to “lock” the culture do like this:

int price = 2795000;
string priceStr = string.Format(new CultureInfo("en-US"), "The price is {0:C}", price);


That would format it as $ instead, giving priceStr the value “$2,795,000.00″

I also found a great list of (all?) the possible ways to format using string.Format() that I can highly recommend here:

Free Windows Phone 7 Toolkit e-book

Today I found a new e-book, that I just have to recommend, which explains the Windows Phone 7 Toolkit in depth. It looks really good, covering most controls in detail, and giving some nice examples. This will probably be a good complement to the examples that comes with the toolkit. The book is written by Boryana Miloshevska, an experienced software developer. It can be downloaded for free here:

Update: I can also recommend the free e-book “Programming Windows Phone 7″ by Charles Petzold ( which is also a great resource for WP7 development.

Gasmackar submitted to Windows Phone marketplace

I have now submitted a new application to marketplace for certification, Gasmackar, which helps you find natural gas stations in Sweden. It shows the price and address, and allows you to easily navigate there using Bing Maps. It also features a live tile displaying the current average price for natural gas in Sweden. All information is from, a huge thanks to them for supplying the data. Below are some screenshots:


The application will soon be available in Windows Phone Marketplace. I will update with a link when it is available!

SMS-Biljetter 1.4 update coming soon

I have now submitted version 1.4 of SMS-Biljetter to Windows Phone 7 marketplace.

Not a lot of changes this time, but I have added the following places to buy tickets:

- Uppsala Regionbussar

- Länstrafiken Kronoberg (Växjö)

The update will be available in Marketplace in a few days.

SMS-Biljetter (SMS-Tickets) 1.3 now available in WP Marketplace

SMS-Tickets 1.3 is now available in Windows Phone Marketplace. I have rewritten the whole application to improve performance, and are now also using databases to store information instead of XML files. But the main features is that it is now fully compatible with Windows Phone 7.5 (Mango). After a user request I have also added support for prefixes for phone numbers.

With mango also comes 2 sided tile support and multiple tiles, so finally you can pin your favorite tickets to the start screen and create a ticket in just one click! The live tile will on the front show which city the ticket is for. The backside will show more information as what ticket type (Adult, child, etc.), how many zones, if a prefix is used, and/or if night price is chosen.

Change log:

- Pin tickets to the start screen
- View the bus companies website right inside the app
- Add and use prefixes for phone numbers
- Support for Windows Phone 7.5
- The app is now completely free!
- Updated information about most of the bus companies
- Added the bus company “Din Tur” (Sundsvall)




Download the application here

Sok Operator (Search Carrier) is now in marketplace

My next app has now been published in marketplace! It is called “Sök Operatör” (Serach Carrier). Simply put the app shows the carrier of a specific phone number (only Swedish phone numbers). Perfect when you want to know if you can afford calling your friends! Blinkar

The app is very simple, just enter a phone number or pick one from your contacts, and press search and after a few seconds the carrier name is presented.

Here are some screenshots:




Multiple selection in Listpicker

I thought I would write a quick how-to about how to use the ListPicker for selection of multiple items.

First create a ListPicker in XAML with a few deafult strings like below:

<toolkit:ListPicker Name="myListPicker" Header="Countries" FullModeHeader="CHOOSE COUNTRIES"
SelectionChanged="myListPicker_SelectionChanged" SelectionMode="Multiple">

Notice the attribute SelectionMode=”Multiple”, which sets that the user can select multiple items, we also added an event handler for the SelectionChanged event.
Note: To use < sys:string > you need to add xmlns:sys=”clr-namespace:System;assembly=mscorlib” at the top in the < phone:PhoneApplicationPage> tag.

Now in the construct for the page, add the following code:

myListPicker.SummaryForSelectedItemsDelegate = SummarizeItems;

This assigns the function SummarizeItems to summarize the string to be shown for the selected items. Let’s create that function now:

private string SummarizeItems(IList items)
   if(items != null && items.Count > 0)
      string summarizedString = "";
      for(int i = 0; i < items.Count;i++)
         summarizedString += (string)items[i];
         // If not last item, add a comma to seperate them
         if(i != items.Count - 1)
            summarizedString += ", ";
      return summarizedString;
      return "Nothing selected";

This function gets an IList with all selected items and we just loop through them and add to a string with a comma between every selected item. Then we return the string, which will be shown when the list picker is in normal mode.

Hope you enjoyed this quick how-to!

Enable Windows 8 metro apps on netbooks

A few days ago I installed the Windows 8 Developer Preview on my netbook which has a 10.1″ screen. The problem was that none of the metro apps would launch. Apparently metro apps do not run on screen resolutions below 1024×768 and my netbook has 1024×600. But luckily there is a work around. You have to enable downscaling and increase the resolution. Here is how you do it:

1. Press “Win”+R on the keyboard to open “Run”
2. Write “regedit” and press “ok”.
3. In the registry editor navigate to:
4. In here you will find several keys that look like this:
Inside SOME of those keys you will find keys named 0000 and 0001
5. Inside each key called 0000 and 0001, find the entry called “Display1_DownScalingSupported”, change that value from 0 to 1.

6. Restart your computer
7. Now you can change your resolution to 1024×768, and the metro apps should now work!

Notice: Change in the registry at your own risk!

Media Remote for WP7.5 mango now in marketplace!

Media Remote with support for Windows Phone 7.5 mango is now available for download/update in the Windows Phone Marketplace! If you have used Media remote before you will need a new version (1.2) of the server software available here.

Feature Highlights:

- Works with ALL types of Spotify accounts!

- Play/Pause and choose tracks in Spotify

- Control the volume

- Search for artists, albums, and tracks to play

- Pin tracks, artists, and albums to your start screen

- Share what you are listening to with your friends via Twitter, Facebook, and Windows Live

- View information about albums