Handling navigation loops and redirection in Windows Phone apps

Hi,

One more shortie 🙂

Case 1: Sometimes in apps there are pages like LoginPage that are completely transient and should be removed from backstrack right after navigating away from them.

Case 2: Sometimes in apps there are pages like PaymentPage or CabinetPage that require authentication and user has to be redirected to LoginPage and after successfull that can go to destination.

Solution:

NavCoercion

Sources of FluentCoercion: https://navcoerce.codeplex.com/
Please feel free to share with your ideas how to improve it.

Showing different Application Bars depending on some ViewModel logic

Hi,

Will be a short post 🙂 Have just a few spare minutes.

In the example i bind appbar on PaymentStatus of my Order, but sometimes it makes sense to bind appbar on SelectedIndex of  Pivot/Panorama.

Usage:

Изображение

GenericConverter is a nice converter that is quite usefull to implement different views depending on some enums on numbers or strings. Actually it is a bit error-prone and should be used carefully. In complex cases it is better to write specific controls.

Изображение

 

 

Windows phone LINQ2SQL provider performance issue/optimization

Hi all 🙂

I was looking at application DB performance and found that there is a query that runs for quite a long time.

This is how it looks like:

image

Usual steps for situations like that are:

1. Get a database from device.

C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Tools\IsolatedStorageEx
plorerTool>ISETool.exe ts de {product GUID} c:\

2. Open LINQPAD and create a connection to the database via SQL CE 3.5 provider.

SNAGHTML106936de

3. Copy the query from your code to LINQPAD, execute it and have a look at generated SQL code. At that moment probably you will see some issues in SQL code.

image

4. Next step is to see how this SQL code is executed, for that we should copy SQL to SQL Management Studio and execute it with actual execution plan. Don’t forget to substitute SQL
parameters with values from comments. Sorry for the screenshot of russian version of SSMS .

image

Analyzing execution plan is quite interesting and difficult task. I can hardly describe this process in proper way. The simplest thing that we should avoid in most (but not all) cases is table scan which is quite slow. Usually this is fixed by creating an additional index. But anyway I recommend to google a bit on this topic.

You can play a bit with query and indexes and try to execute query again. When performance gets to good level – you should modify your datacontext in code or regenerate it with SQLMetal. If you’ve made some modifications of query, it can be a challenge to make a projection of new SQL to the LINQ query. I can’t give any recommendations. But usually it is rather simple.

 

DBLog.cs – class that helps logging SQL generated by DataContext on WP7

Preventing preload of pivotItems in Pivot control on Windows Phone 7

Hi,

Probably all of us used Pivot control from WP7 SDK.  By default it preloads the pivotItem we see, and 2 additional items: to the left and to the right.

 

Sometimes it is useful not to do that preloading if you want to show first pivotItem ASAP.

This can be easily done by deriving from SDKs Pivot control and overriding OnLoadedPivotItem method.
Currently it looks like that:

image

 

When some pivotItem is loaded it checks whether its neighbours were already loaded. If not – it preloads them.

I created a derived class that overrides that method and does nothing.
WARNING: We will lose LoadedPivotItem event.

image

 

Other pivot will load first time user navigates to them.

Exploring Windows Phone 7 Silverlight sources

Hi,

If you work on WP7 project, probably you wanted to look into source of Silverlight classes.
In such cases tools like Reflector or Telerik JustDecompile usually can help us.

But this task becomes a bit harder in case of WP7 libraries. The reason for that is that real libraries that contain all the code are hidden in phone ROM and in development we use reference assemblies  that contain only definitions of methods but no code. When we add a reference in Visual Studio the reference usually leads to reference assemble.

Reference assemblies for Windows Phone 7.5 are located at
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone71\

To make successful decompilation we need assemblies with code.
These can be easily get with help of Performance Profiler. When it starts analyzing performance logs it loads all assemblies from the phone ROM.

Assemblies with code can be found at
%PROJECT_FOLDER%\PerformanceLogs\AssemblyCache7.10.7720

11-11-2011 21-02-52

To save your time, I put these assemblies in archive. You can download them with this link

Archive with DLLs (3.5MiB)

Windows Phone 7 : ArgumentException “The parameter is incorrect” bug in Pivot.Remove()

Hi,

First of all i would like to say that im very glad to start my first blog. I’ll write here some ideas on WP7 and C# programming.

My first post will be rather short. It is dedicated to weird bug in Pivot control  that comes with Windows Phone 7 SDK.

Short description:

1. You create a markup with pivot control and some pivot items in it.  Important Note: At least 1 pivot item should have complex header. By complex i mean a non-string header but a header with some controls in it.
2. At some point in application flow you want to remove the PivotItem from Pivot.

Here you probably will get an ArgumentException like on the image below
exception

 

It is hard to say what exactly causes this exception, but it seems that there is a but in logic that manages headers in Pivot control.

For the project i’m currently working on i created a workaround. It is a class derived from Pivot that has 3 methods that help with this task.

In current implementation when user tries to scroll to hidden pivot item it just skips it. To keep UI consistent we make pivotItem Header null and restore it to previous value when UnHidePivotItem is called.

 

Links to sources:

1. https://www.dropbox.com/s/uqb4p2rqczybbik/PivotWithHiding.cs – class only
2. https://www.dropbox.com/s/ls281kfsa3ibvgr/PivotRemoveBugWorkaround.zip – full project where you can remove and add pivot items by clicking appBarButtons