Determine internet connection speed of the device.

Hi again,

Some day i was staying in metro and testing the app i’ve been working on.  Something went wrong. Issue was that images were not loaded as device was connected to the internet via GPRS.

App should load smaller images.Luckily server supports multi-res image output.

I defined 4 important for us states
11-04-2013 17-58-15

There are 3 ways of getting conenction speed on device. And only 1 of them works properly.
1. HttpWebRequest and WebRequestExtensions.GetCurrentNetworkInterface (not reliable)
2. DeviceNetworkInformation.ResolveHostNameAsync (breaks tombstoning)
3. Socket and SocketExtensions.GetCurrentNetworkInterface

The third option works like a charm.

Here you can see how socket to Googles Public DNS server is opened and NetworkInterfaceInfo is extracted. Speed assumptions are based on NetworkInterfaceInfo.Bandwidth
11-04-2013 18-17-20

Basing on ConnectionSpeed and on DeviceSpeed
11-04-2013 18-04-02

we decide what image to load via nice matrix
11-04-2013 18-05-54

All the code is in the Zip file on the dropbox.
https://www.dropbox.com/s/5ib47l93j6nwg1v/ConnectionSpeed.zip

Important:  Don’t forget to invoke ConnectionSpeedManager.CheckConnection() in Apps OnLaunch and OnActivate methods

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.

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