Martin Suchan – BloQ Random #WPdev stuff

4Nov/132

How to debug most common memory leaks on WP8

When developing Windows Phone application, which is more complex than just 3 screens and couple lines of text, you'll probably face the well-known problems of memory leaks. Even when using modern platform as Windows Phone 8, without pointers, with Garbage Collector, IntelliSense and everything, it is still quite easy to experience memory leaks in your apps.

In this article I'll go through 3 most common problems that are causing leaks when developing Windows Phone apps: Images, abandoned Pages and leaks in native controls. I'll also shown you simple trick, how to find your leaks early in the development and not two weeks before project deadline ūüôā

26Sep/139

Shared localization for Windows Phone 8 and Windows 8 apps using Portable Class Libraries

When developing Windows Phone 8 or Windows 8 app for more wider audience, you need to think about the localization. Unfortunately the localization on each platform uses completely different approach:

On Windows Phone 8:

  • Standard resx files with strings for each language are used.
  • The default language, for instance "en", has localization in file without any suffix, typically just AppResources.resx.
  • Other languages uses files with culture specific suffix, like AppResources.de.resx, AppResources.cs.resx, etc.
  • For supporting non-default languages it's required to check the additional languages in WMAppManifest.xml file and in the project settings as well
  • Localization in XAML is done typically via databinding to viewmodel class, that has instance of AppResources class, typically:
  • <TextBlock Text="{Binding Loc.AppTitle, Source={StaticResource Localization}}"/>
  • in AppResources.resx: ¬† | ¬† AppTitle¬†¬† | ¬† Hello world! ¬† |
  • For accessing the localized string programatically you can use:
  • string text = AppResources.AppTitle;
  • Globalization and localization for Windows Phone

On Windows 8(.1)

  • Windows 8 uses for localization new file types ending with .resw, but actually they use completely equal structure as WP8 .resx files.
  • Each file must be placed in a separate folder, for instance English localization should be placed in Strings/en/Resources.resw, German localization in Strings/de/Resources.resw
  • There are no automatically generated Designer.cs files for these resw files, but you can create manually ResourceLoader class for returning localized strings.
  • In Windows 8 the localization of Controls in XAML is done differently. Rather than assigning directly values using databinding, you just name each localizable control with x:Uid property and then add entry for localizing such property directly into resw file:
  • <TextBlock x:Uid="TextBlock1" Text="DesignTimeText"/>
  • in AppResources.resw: ¬† | ¬† TextBlock1.Text ¬† | ¬† Hello world! ¬† |
  • For accessing the localized string programatically¬†you can use:
  • ResourceLoader resourceLoader = new ResourceLoader();
    string text = resourceLoader.GetString("TextBlock1.Text");
  • Application resources and localization sample (Windows 8.1)

As you can see, the recommended localization uses completely different approach in Windows Phone 8 and Windows 8. Sharing resx files using links, or even copying them or renaming is just not feasible to maintain. Beside these obvious differences, there are even other caveats:

  • Accessing localized strings in Windows 8 projects programatically¬†is really cumbersome and you can make simply error, because you have no direct compile time check, that "TextBlock1.Text" actually exists in the resw file.
  • You cannot share any localized XAML code between Windows Phone 8 and Windows 8, because of the different localization method

Let's see, how to solve this mess once and for all

12Jun/130

Pro WP8 AppBar management with AppBarUtils

When developing apps for Windows Phone 8, every developer needs to know how to create and manage the App Bar. The problem is you cannot use databindings and/or localization in App bar buttons and menu items, you also cannot bind the colors or enabled state or even use commands bound to the buttons.

Most apps I've seen uses tedious programmatic initialization in code, repetitive entering of same resource values, or even not localized App bar at all. But there is an easy solution - the AppBarUtils library.

With this library you can use databinding for all AppBar properties, use Commands, even use dynamic app bar content for currently selected pivot/panorama item or your own state like logged-in/logged-out user. Let's see, how to do it.

Filed under: .NET, WP8, WPdev Continue reading
31May/133

Image path databinding in WP8 and Windows 8 apps

I don't like lengthy articles, so let's make it short and easy.
When you are developing Windows Phone 8 or Windows 8 "modern" apps, you surely want to display images in it.
For displaying images the well known Image element is used:

<Image Source="imagepath"/>

The imagepath can have multiple values, it can be:

  • Uri address to image located on the Internet
  • path to image located in app resources/app installation package
  • path to image located in app isolated storage

The interesting point is that I've discovered only today that it is actually possible in WP8 apps to display images located in isolated storage directly just by defining the Source, without any loading to Stream and BitmapSource. That's right, even if you search on StackOverflow or on MSDN  how to display images located in isolated storage using path in WP8, they tell you it's not possible.

Yes, it is possible, and the whole magic it so use absolute image path using the StorageFile.Path property. Now you know the secret, but let's check it in detail.

30Jul/122

Pro Live Tiles for Windows Phone

In this short article I'll show you the most interesting way, how to create custom Live Tiles using generated Png images.