Saturday, August 25, 2012

Issues/differences encountered converting WP7 apps to Windows 8

Tone the Visual Studio 2012 MENUS DOWN

Changing the All-Caps menu in Visual Studio 2012 to something more readable. Install the VS Commands extension

Tools > VSCommands > Options > IDE Enhancements > Main Menu > Change Main Menu letter case

int? Properties in custom user controls

Binding to a nullable int property in a custom user control produces the following error:

Failed to create a 'Windows.Foundation.IReference`1<Int32>' from the text '40'. 

Internally most of the .NET primitive types are converted to equivalent Windows Runtime types. IReference<T> is the Windows Runtime equivalent of Nullable<T> in .NET.

"Setting nullable properties [in] custom controls is not a supported scenario".

XAML Error : Value Type Nullable is not allowed on property in XAML Windows 8 Dev Tip: Nullable Dependency Properties and Binding

Tap Event

The Tap event with GestureEventArgs becomes a Tapped event with TappedRoutedEventArgs


MessageBox.Show is replaced by Windows.UI.Popups.MessageDialog

MessageDialog.Show("Some Message");
async private void ShowDialog() {
    await new Windows.UI.Popups.MessageDialog("Some Message").ShowAsync();

There is no WebBrowserTask

WebBrowserTask task = new WebBrowserTask();
            task.Uri = new Uri("");
async public void Show()
            await Launcher.LaunchUriAsync(new Uri(""));

General Namespace issues

"System.Windows" with "Windows.UI.Xaml"

Differences in StaticResource Styles


Style="{StaticResource PhoneTextTitle3Style}

Windows 8

Style="{StaticResource SubtitleTextStyle}"

Text Styles

WP7 NamePossible Windows 8 Style

Brush Resources

WP7 StylePossible Windows 8 StyleDescription
PhoneChromeBrushAppBarBackgroundThemeBrushUsed to match the application bar color

Theme Brushes

No direct equivalent for the Pivot control

"The Windows Runtime does not include the Pivot and Panorama controls available in Silverlight for Windows Phone. These controls are designed for the phone form factor, and help users navigate experiences that are larger than the phone screen. Your Metro style apps will usually have more screen space, and should take advantage of the greater flexibility of the Grid control. You can also use the FlipView control to provide a simple paging experience."
A WinRT behavior to turn a FlipView into a kind of Windows 8 Panorama

No direct equivalent for the PhoneNumberChooserTask

Use the Contact Picker contract. Sample

        private async void ActionButtonChoose_Click(object sender, RoutedEventArgs e)
            var picker = new Windows.ApplicationModel.Contacts.ContactPicker();
            picker.CommitButtonText = "Select";
            picker.SelectionMode = Windows.ApplicationModel.Contacts.ContactSelectionMode.Fields;
            var contactInformation = await picker.PickSingleContactAsync();

            if (contactInformation != null && contactInformation.PhoneNumbers.Count > 0)
                  txtDail.Text = contactInformation.PhoneNumbers[0].Value;

No direct equivalent for the SmsComposeTask or EmailComposeTask

Windows Phone 7

SmsComposeTask composeSMS = new SmsComposeTask();
composeSMS.Body = "Greetings";

For WinRT there is SendSmsMessageOperation, but the documentation currently says:

Note This functionality is only available to mobile operator apps and Metro style apps given privileged access by mobile network operators, mobile broadband adapter IHV, or OEM.

Another option is to create a mailto URI. I haven't tested this yet, but it looks good in theory.

var mailto = new Uri("mailto:?");
await Windows.System.Launcher.LaunchUriAsync(mailto);

Share the content via the DataTransfer API. How to share text (Metro style apps using C#/VB/C++ and XAML)

No direct equivalent for the SQL CE database built into Mango using Isolated Storage

IsolatedStorageSettings isn't available.

Switch to Windows.Storage.ApplicationData.Current.RoamingSettings or another class under Windows.Storage.ApplicationData.

PhotoChooserTask isn't in WinRT

Use CameraCaptureUI

private async Task CapturePicture()
    var dialog = new CameraCaptureUI();
    dialog.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png;

    var file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
    if (file != null)
         IRandomAccessStream imageStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

    return string.Empty;

How to Capture Images w/ the WebCam in WinRT (C#) applications.

Binding doesn't have a StringFormat option

So a binding like Text="{Binding WordsPerMinute,StringFormat='WPM: {0}'}" results in the errors:

The member "StringFormat" is not recognized or is not accessible.
The property 'StringFormat' was not found in type 'Binding'.


WrapPanel doesn't (yet) exist in WinRT

See also: