The parameter is incorrect

17 Dec

For the last couple of months we have been working on some different Windows Phone projects. Yesterday we ran into an exception in one of our projects. Sometimes when we navigated into a specific page we got an argument exception “The parameter is incorrect”. The exception was inconsistent but we got it more often when debugging compared to when we ran our project in release mode.

2012-12-17_013042

First step was of course to enable as much debugging info as possible which resulted in this StackTrace:

at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.Collection_AddValue[T](PresentationFrameworkCollection`1 collection, CValue value)
at MS.Internal.XcpImports.Collection_AddDependencyObject[T](PresentationFrameworkCollection`1 collection, DependencyObject value)
at System.Windows.PresentationFrameworkCollection`1.AddDependencyObject(DependencyObject value)
at System.Windows.Controls.UIElementCollection.AddInternal(UIElement value)
at System.Windows.PresentationFrameworkCollection`1.Add(UIElement value)
at System.Windows.Controls.ItemsControl.AddVisualChild(Int32 index, DependencyObject container, Boolean needPrepareContainer)
at System.Windows.Controls.ItemsControl.AddContainers()
at System.Windows.Controls.ItemsControl.RecreateVisualChildren(IntPtr unmanagedObj)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at Microsoft.Phone.Controls.Pivot.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)
at MS.Internal.XcpImports.MeasureOverrideNative(IntPtr element, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
at Microsoft.Phone.Controls.PhoneApplicationFrame.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)

The page was actually pretty simple – a Pivot control with 4 items each containing a usercontrol. So with the StackTrace in mind we looked for some dynamically sized controls within our usercontrols . First of all we tried to change the Pivot control with a Panorama control – still got the exception. So we had to go through our code and line by line we removed content – still got the exception. In the end we had removed all the content inside our usercontrols and the page was stripped down to contain only the most necessary properties. Still got the exception.

In the end I stumbled upon the naming of our usercontrols – not in the page but the x:name within the usercontrol itself. Some of the usercontrols had been giving names that was used as part of some animation. What caught my eye was that two of the usercontrols got the same x:name. I tried to change one of the names and boom! Problem solved.

So to take this little issue to the test I created a small sample demonstrating the issue. The sample automatically navigates from one page to another and back until the exception is through (takes about 2-5 minutes).

The issue is on both Windows Phone SDK 7.1 and 8.0.

// thomas

Spotify – we will do your Windows Store app for free!

14 Dec

It’s a shame to see that Spotify still isn’t available for Windows Phone 8 and Windows 8. I understand that they probably have a big backlog and can’t have apps of this size available in just a few weeks.

However Windows 8 have been available for some months now and we haven’t heard anything from Spotify about a realistic release date. The result is obvious – users cancel their subscriptions and find another musicplayer. Just check out the forums and the comments in this thread – users have an excellent alternative in Xbox music.

A few weeks back my team and I decided to take a radical step – we offered Spotify to do the Windows 8 app – for free. We have developed our share of apps for the Windows Store; 20+ apps ranging from video-on-demand apps to homebanking apps.

We still haven’t heard anything from Spotify.

http://community.spotify.com/t5/Spotify-Ideas/Windows-8-Metro-App/idc-p/223348#M14834

Resource Dictionary for Windows Phone

6 Nov

One of the missing templates in the Windows Phone SDK is Resource Dictionaries. If you work with styles and resource dictionaries, the missing template is a big thing.

Worry no more! I have created the template you need!

You can get them ItemTemplate from my SkyDrive and install it in your ItemTemplate folder, typically located here:
C:\Users\[USERNAME]\Documents\Visual Studio 2012\Templates\ItemTemplates\Visual C#\Windows Phone\1033

// thomas

Installation Folder in Windows Phone 8

2 Nov

The installation folders for Windows Phone apps (also known as appdata) are read-only and reading data from files in the folders hasn’t always been the best experience. We have been able to use GetResourceStream to stream files from the appdata folder and DataContext to work with a local database.

With Windows Phone 8 we got some improvements. We got a new property of the current package called InstalledLocation. It returns the installation folder as a StorageFolder and using the Path property it’s possible to get the full path of the installation folder. Using the StorageFolder we are able to work with the files in the appdata folder.

The content of the appdata folder can easily be accessed using the appdata or ms-appx URI scheme names. Although the two schemes point to the same location, there is an important difference in the usage of the two. Use “ms-appx:///” for accessing the appdata folder with APIs that are part of the new Windows Phone Runtime (part of the Windows namespace). In all other APIs use “appdata:/”.

If we want to get a file asynchronisly we can use Windows.Storage.StorageFile.GetFileFromApplicationUriAsync
to access the file. As the API is part of the new Windows Phone Runtime, it is required we use “ms-appx:///” to access our file:

If we just want to specify an Uri we can use “appdata:/”:

// thomas

Templates in Visual Studio 2012

1 Nov

For some time now I have developed XAML based Windows Store apps using Visual Studio Ultimate 2012. The apps are built for clients as part of my company targeting consumers. What I’m trying to get to is that I use Visual Studio and the built-in templates quite a lot. And with that also comes some features requests :)

The built-in solution templates are fine. They are good for getting started and learning about the new guidelines for building Windows Store apps and Windows Phone apps. I guess that every Windows Store developer have tried to build a demo app based on the templates. So my issues comes to adding new items to my projects. Every time I add a new Page or new UserControl to a project, I have to delete 20 lines of comments in the XAML and in the code-behind (especially for Windows Phone 8). The comments describe how to get started using the items and how to read more about the type of item. This is great information for new developers or developers getting to know the platform – but it’s not appropriate in a pro tool like Visual Studio Ultimate. Why not have it in a starter kit or in the Express editions of Visual Studio (only).

To answer a comment that most likely will pop-up – yes I’m aware that it’s possible to customize the content of the items. It just shouldn’t be necessary in pro tools like Visual Studio. I think.

// thomas

Where is the Skype app for Windows Phone?

1 Nov

Yesterday I wrote a blog post asking about the missing Build app for Windows 8. Rumors says the app is built but failed certification hence not available for the attendees – it has not been confirmed by Microsoft!

Until today Nokia Lumia 800 have been my primary phone. Today I’m taking my new Nokia Lumia 920 (thank you Microsoft and Nokia!) and doing it the only true way – making it my primary phone. It’s a big phone but the technical features are awesome and combined with Windows Phone 8 I expect a great experience. I have customized it (making it my own) and I already love some of the new features – especially the “Rooms” feature – it’s really communication made easy!

For the last couple of months I have been addicted to Skype. With the new Skype app for Windows 8 my expectations for the running the app on a Windows Phone 8 device was pretty high. I have been running Skype on my Lumia 800 but it’s almost useless without a front faced camera. Open the store, searching for Skype and gets several results – but no Skype app?! Frustration kicking in! Searching the internet to get an answer.

Turns out that Skype have built a new app from the ground up for Windows Phone 8 supporting some of the new awesome features available in the Windows 8 app and using the new features available in Windows Phone 8. Skype have announced that it is soon-to-be available. Read the full story and get an overview of the new features at their blog or take a look at this video.

// thomas

Where is The Build App?

31 Oct

Yesterday at the excellent keynote at Build, Steve Ballmer clarified the importance of building great apps for the Windows platform. To back it, Microsoft provided all attendees with a Surface – if we promised to develop lots of apps. With the keynote in mind I searched the Windows Store for the Build App – I couldn’t find it. Instead I tried the Build website (www.buildwindows.com) on my Surface. I quickly realized that some part of the website was built with touch in mind – but certainly not most of it.

So my question to Microsoft is pretty simple: Why haven’t you build an awesome Build app that would inspire developers to build great apps?

You have a really strong support in your knights (the MVPs) that most definitely would have built it for you.

UPDATE (2012-11-02):

The Build app is now available at the Windows Store.

Build 2012 app for Windows in the Windows Store
http://apps.microsoft.com/webpdp/app/0c51433d-4d6b-4e51-a274-86611f732fca
Learn more about Build 2012 by Microsoft Corporation and download it from the Windows Store

// thomas

Using the ProgressIndicator in the SystemTray in Windows Phone

30 Oct

In many cases Windows Phone developers implement and place their own progress indicators in Windows Phone apps.

When you add a new PhoneApplicationPage to the app it will by default set the IsVisible property on the SystemTray to true on the page. This is done in XAML by default in the VS template.

The system tray can also be accessed from codebehind. It is possible to set properties like IsVisible during the Loaded or OnNavigatedTo event wired up in the codebehind. It’s not possible to set the system tray as part of the pages constructor.

The system tray got a build-in progress indicator (ProgressIndicator) located in the top of the system tray. The progress indicator on the system tray can be used in the application to show progress in a uniformed way. However to be able to use the progress indicator you first need to instantiate it.

Once it’s instantiated you can set all the regular properties like Opacity and Color on it and it’s possible to reuse this “default” progress indicator in a very easy manner. It won’t take long to make this a bit more generic which you most likely would do if you’re building an app with more than one or two pages.

// thomas

Tiles and Notifications in Windows Phone 8

30 Oct

The tile is the front door to your app. A nice tile can mean the world to your app and the usage of it. Some developers/companies manage to use this opportunity and make great static and living tiles.

New Tile Sizes

With Windows Phone 8 we have a new set of sizes and templates available for our tiles. The user have the opportunity to customize the size of the tile based on three sizes: small, medium and wide. It is required to implement small and medium sizes tiles but wide is optional. The supported sizes is set using the redesigned Manifest file.


Screenshot from Visual Studio 2012

Windows Phone 8 supports multi resolutions. Tile icons (and app icons) are defined for WXGA (768×1280) and are automatically scaled to work for WVGA and 720p.

New Templates

Windows Phone 8 supports three templates: flip, iconic and cycle.

It is not possible to update the template for the default tile programmatically – it will require and update of the app. The template for secondary tiles can be updated programmatically. Furthermore it is not possible to know which tile size the user has pinned to the start screen so all properties should be set for the supported tile sizes.

Flip Template

The flip tile template flips from front to back and support all three available sizes: small, medium and wide. The properties for the flip tile template is available using the FlipTileData class.


Image is taken from the SDK help file.

The small flip tile is 159×159 pixels and only allows a small background image (SmallBackgroundImage) and a counter (Count).

The medium flip tile is 336×336 pixels and allows a background image (BackgroundImage), title (Title) and counter (Count) on one size and a backbackground image (BackBackgroundImage), back title (BackTitle) and back content (BackContent) on the other side.

The wide flip tile is 691×336 pixels and allows a background image (WideBackgroundImage), title (Title) and counter (Count) on one size and a backbackground image (WideBackBackgroundImage), back title (BackTitle) and back content (WideBackContent) on the other side.

Iconic Template

The iconic tile template displays an image in the center of the tile and support all three available sizes: small, medium and wide. The properties for the iconic tile template is available using the IconicTileData class.


Image is taken from the SDK help file.

The small iconic tile is 159×159 pixels and only allows a small icon image (SmallIconImage) and a counter (Count). The icon size is 110×110 pixels.

The medium iconic tile is 336×336 pixels and allows an icon image (IconImage), title (Title), background (BackgroundColor) and counter (Count). The icon size is 202×202 pixels.

The wide iconic tile is 691×336 pixels and allows a small icon image (SmallIconImage), title (Title), counter (Count) and three lines of content (WideContent1, WideContent2, WideContent3). The icon size is the same as the small iconic tile.

Cycle Template

The cycle tile template cycles between 1 and 9 images and support all three available sizes: small, medium and wide. The properties for the cycle tile template is available using the CycleTileData class.


Image is taken from the SDK help file.

The small cycle iconic tile is 159×159 pixels and only allows a small background image (SmallBackgroundImage) and a counter (Count).

The medium cycle tile is 336×336 pixels and allows a title (Title), counter (Count) and between 1 and 9 background images (CycleImage1, CycleImage2…).

The wide cycle tile is 691×336 pixels and allows the same properties as the medium cycle tile.

// thomas

Windows Phone 8 SDK is now available

30 Oct

Today during the Build keynote the Windows Phone 8 SDK was announced. Using the SDK you can build both Windows Phone 7.5 and Windows Phone 8 apps in Visual Studio 2012 on Windows 8.

The SDK is available here: http://www.microsoft.com/en-us/download/details.aspx?id=35471

Stay tuned for a series of blog posts on the new features available in the Windows Phone 8 SDK.

// thomas