Thursday, March 24, 2011

Making tombstoning easier [#wp7dev]

Sometimes tombstoning can be tricky.
Often it takes a lot of boilerplate code.

Things just got much easier.

Now all it takes is 2 lines of code:
    protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedFrom(e);

        this.SaveState();  // <- first line
    }

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        this.RestoreState();  // <- second line
    }
Get all the tombstone helper goodness from http://tombstonehelper.codeplex.com/ Already got some tombstoning support in your app but not handling the scrollviewer scroll position? Just do this:
this.SaveState(typeof(ScrollViewer));
Head on over to codeplex: http://tombstonehelper.codeplex.com/ for more details and please be sure to let me know what you think.

Wednesday, March 16, 2011

Binding to static classes in Windows Phone 7

It's a common request to be able to bind to a global variable in various parts of an application. It's often common that such variables are static.
This question seems to pop up in forums rather regularly and often the advice given is that this isn't possible or to include the "global" variable as part of the model being used as the DataContext of the page. Such duplication of functionality in the model is a bad idea and totally unnecessary.

It's not possible to bind to a static class as binding requires an object instance.
You can, however, bind to static properties of a class.

So we can bind to the static properties of the following.

namespace StaticBinding
{
  public class MyStaticClass
  {
    private static string myStaticProperty = "my static text";

    public static string MyStaticProperty
    {
      get { return myStaticProperty; }
      set { myStaticProperty = value; }
    }
  }
}

We can then create an application level resource which we can actually bind to:

.. xmlns:myns="clr-namespace:StaticBinding"


  

(Sorry, don't know why the syntax highlighter has forced upper case - I'm sure you're smart enough to work out what should and shouldn't be upper case though. ;)

With the above configured we can then bind to our global property in any page we wish. We just need to set the `Source` and `Path` of the binding.

..


.. 

A nice upside of this is that you even get intellisense on the `Path`. (Assuming you've set the `Source` first.)



X-Ref: http://stackoverflow.com/questions/5323052/data-binding-a-string-variable-of-static-class-to-textblock-in-phone-7/5325257#5325257

Thursday, March 10, 2011

Gotchas when forcing the theme colour in a Windows Phone 7 app

Windows Phone 7 support two background themes: light and dark.

When combined with the accent colour, this allow the user a level of customization and personalization of their device and the applications they use.

As a general rule it's good to allow your application to reflect the theme and accent colout the user has selected. Sometimes, however, you may want to "force" the theme of the app. This means that regardless of the them the user selects the application always looks the same.

Look at these two versions of the same app:
The image on the left was taken with the dark them selected and the one on the right with the light theme.
It looks like all is fine.

However, if we want to support the inclusion of the `SystemTray`, so that the user can see the time, battery level, network conection status, etc. then the system theme colour will show through and there's nothing you can do about it. Apart from not include the SystemTray, of course.

If you want to use a MessageBox in your application then you'l have a similar issue. This is what the default MessageBox looks like when a light theme is selected but a dark theme is forced.

The solution is to make your own version of a MessageBox.

Creating your own version of a message box is relatively simple. Creating your own SIP/Keyboard is a lot more complicated if you want to recreate all the functionality of the built in one.
My advice, don't force the theme unless you have a REALLY good reason and have the time and patience to deal with all the consequences.

Wednesday, March 09, 2011

#WP7Dev app feedback #6

Here's the feedback I recently gave to the creator of an app.

This is part of my series of app reviews.

In summary, I said it was "a nice app which is well executed".

Here's the feedback:

  • It would be nice if the main screen would remember the selected panorama item after being tombstoned.
  • When viewing items and swiping from side to side, there's no indicator of when the end of the list of items has been reached.
  • When viewing an item, tapping it to return to the main menu was, initially, unexpected and caused me to accidentally navigate backwards several times. Especially/even when scrolling down.
  • If viewing the item summaries for a single category, it's not clear what I'm navigating between when I swipe from side to side.
  • If viewing an item and the app is tombstoned, I would expect the app to display that item again when I navigate back to it.
  • If only one category is configured, on the first panorama item, is it necessary to have the "all items" option as well as the category.
  • In trial mode, it's possible to view articles of featured items, but not other items. This inconsistency was surprising.
  • When adding a new feed it would be good to also add this to a new category, not just select from existing ones.
  • When adding/editing a feed, is a cancel option really necessary? Can you not just rely on the back button to perform a cancel action?
  • When adding a category the entered text is required to be at least 2 characters long. This includes spaces. This means that it's possible to create categories made just of spaces.
  • The detecting of duplicate category names also doesn't include spaces at the start or end of the entered text which means that duplicates can, seemingly, appear to be created.
  • When a featured item is selected but the main progress bar is still being displayed, this appears over the top of the popup.
  • When a featured item is marked as read from the popup all featured items are reanimated. This takes time and makes the app seem unresponsive and means it's hard to quickly view multiple featured items and mark them read at the same time.
  • In the email created from the about screen, you may want to include the version number of the application. This will likely be helpful to you when investigating any reported error or problem. (Especially if someone is reporting a bug you think is fixed.)

Tuesday, March 08, 2011

#WP7Dev app feedback #5

Here's the feedback I recently gave to the creator of an app.

This is part of my series of app reviews.

In summary, I said it was "a simple, well executed app".

Here's the feedback:

  • On the main/menu page I would disable scrolling of the options/list as everything fits on the screen without needing to scroll.
  • When searching the word list it would be good to indicate when no words match the entered text. This is generally preferable to just leaving a blank screen as it makes it clear that there are no results to display.
  • Add tombstoning support to the search function so that on returning to the application it looks as it did when the user navigated away.
  • When using the next and previous buttons to navigate, I would recommend either making the list wrap around (so that selecting previous from the first item goes to the last item-and vice versa) or disable the previous button when on the first word and the next button when on the last word.
  • In the list, there is uneven capitalization of the first words in sentences.
  • In the list, most (but not all) of the sentences that span multiple lines appear to have a space before the first word. This creates an inconsistent left margin.
  • In the "XXXXX" display, the list is very long and may benefit from using a "long list selector" as in other places in the app.
  • In the "Test Yourself" mode, the page title says "test #N of 20" but it's really it's "question" number N, not "test" number N. I'd recommend changing the text to just be "N of 20".
  • In the "Test Yourself" mode, restrict the clickable space between options to prevent the chances of accidentally selecting an option other than the one intended. With this change it would be possible to remove the need to confirm (apply) the selected option. I find the confirmation step a bit frustrating.
  • If I back out of a test I am prompted to confirm that I wish to make this action as my progress will be lost but if I go back into this option my position in the test is remembered.
  • When the results of the test are displayed there is no clear indication of what the user should do next. How about adding options to try another test or returning to the main menu? I know that the back button can be used to return to the main menu and it's normally a bad idea to duplicate the number of ways you can perform the same navigation but there is currently a dead end. Adding instructions to the page to use the back button to navigate back to the main menu would take up more space and take longer to read than tappable text to do the navigation directly.
  • On the about screen, I would recommend increasing the tappable area around the URL for your website so that it is easier to tap.