Windows Phone 7 Development in the year 2015

You want your Windows Phone app to work on Windows Phone 8.1, 8.0 and 7.1, right? In that case, you must create a Windows Phone 7.1 project in Visual Studio. You cannot do that with Windows Phone SDK 8.1 and Visual Studio 2013, but you don’t have to go back to using Windows Phone SDK 7.1 and Visual Studio 2010 either. Take the middle way, and install Visual Studio 2012 and Windows Phone SDK 8.0.


Converting a Flash Video File for Windows Phone 7

I wanted to be able to view a downloaded video in Flash video format (.flv) on my Windows Phone 7. This proved to be somewhat of a challenge. After installing the Windows 7 Codec Pack, I could open the file in Windows Live Movie Maker, but it froze when I tried to save it to Windows Media Video format (.wmv). So I searched around and found out that VLC Player could do the conversion.

My first attempt was to select Media->Convert/Save, select my input file, press the Convert/Save button, enter an output file with .mp4 extension and select profile Video – H.264 + AAC (MP4). The video was converted all right, but there was no sound. After running with messages turned on (Tools->Messages, Verbosity Level 2) I saw the following error messages: “main error: Failed to create audio filter” and “stream_out_transcode error: Failed to find conversion filter for resampling”. It turned out that the source sample rate was 48 kHz, but the target was 44.1 kHz, and VLC was unable to resample. (Tip: Use MediaInfo to see what your file really contains.)

So I had to change the profile to use 48 kHz sample rate, but in this case, since both the Flash video container and the MP4 container use the same audio format (AAC) I could just check Keep original audio track.


Save output to a Windows video library folder (e.g. “My Videos”) so that it shows up in the Zune videos collection. Now you should be able to sync it to the phone.

Sorting View Model Items Using CollectionViewSource

If you create a Windows Phone 7 data bound application using the template, the item list is not sorted. I found that the simplest way to do that is to use System.Windows.Data.CollectionViewSource. The example on MSDN is perhaps not so helpful, since a static resources are used. You would typically want to bind to dynamic data. I found the solution in a blog post called Use CollectionViewSource effectively in MVVM applications, but decided to implement it a little different. Here is what I did:

In MainViewModel.cs, I kept the Items property of type ObservableCollection<T> and created a new property called SortedItems of type CollectionViewSource:

public CollectionViewSource SortedItems { get; private set; }

The getter of Items returns the CollectionViewSource Source, and the setter of Items updates the CollectionViewSource Source:

       using AccountCollection = ObservableCollection<Account>;

       public AccountCollection Items
            get { return (AccountCollection)SortedItems.Source; }
            private set
                var items = (AccountCollection)SortedItems.Source;
                foreach (var item in value)

In the MainViewModel constructor, I initialize the CollectionViewSource and tell it to sort ascending on a property called Name:

        public MainViewModel()
            this.SortedItems = new CollectionViewSource();
            this.SortedItems.Source = new AccountCollection();
            this.SortedItems.SortDescriptions.Add(new System.ComponentModel.SortDescription("Name", System.ComponentModel.ListSortDirection.Ascending));

Then I changed the binding in MainPage.xaml like this:

<ListBox x:Name="MainListBox" Margin="0,0,-12,0" ItemsSource="{Binding SortedItems.View}">