Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Having multiple App names while sharing AppResources

From Wiki
Jump to: navigation, search

A solution is given how to share resources between multiple versions of an app but allowing for some differences like the app name or an icon.

WP Metro Icon File.png
WP Metro Icon Graph1.png
SignpostIcon XAML 40.png
Article Metadata
Tested with
Devices(s): Nokia Lumia 920, Nokia Lumia 800
Created: influencer (19 Jan 2014)
Last edited: influencer (01 Feb 2014)



In order to keep multiple versions of an app it is desirable to share as much code and resources as possible. Resources present a special problem.

Problem details

Being a good WP citizen one creates multiple versions of the same app:

  • a Windows Phone 7 free version,
  • a Windows Phone 8 free version with extended features

and optionally

  • a paid Windows Phone 8 version and maybe even
  • a paid Windows Phone 7 version.

You localize it in half a dozen languages to reach as many customers as possible.

To reduce work and keep the app maintainable, it is desirable to share as much code and resources between the versions as possible. Sharing code and resources via the 'Add as Link' method in Visual Studio (Share code with Add as Link) is relatively easy. The problem starts when the differences between the versions have to be implemented.

Code differences can be made by defining a preprocessor directive on the project's property page's build tab:

setting preprocessor defines

In code this can then look as follows:


This is easy. But how can you create slightly different resources? Unfortunately, preprocessor defines can't be used with resources. So there has another way to be found to differentiate resources for versions of the app.

An example

Say you have an app named 'TestApp' that you implement first for WP7. You then want to have a WP8 version and you share code and resources via 'Add as Link'. For additional features in the WP8 version you create some new strings in the AppResource. Those are simply not used in the old version. So far so good. No problems yet.

Then you get the idea to earn some money and build a paid Pro version with exciting additional features. You name it 'TestApp Pro'. Now you got a problem. You don't want to copy the resources as you have 6 localized resource files. And all this for one or two different strings, namely the app name and maybe the app icon source!

The solution

I imagine at least two different ways to solve this dilemma:

  • Implement a datasource in code that gives different strings for the different versions (you can use preproc defines here) or
  • implement a value converter (see Collection of Value converters for Windows Phone apps) that filters your strings and replaces the original app name with the Pro app name.

A sample for the first method is this implementation of the LocalizedStrings class that returns a different path dependent on a preproc define:

   public class LocalizedStrings
private static AppResources localizedResources = new AppResources();
public AppResources LocalizedResources { get { return localizedResources; } }
public string AppIconSource
return "images/testapppro99.png";
return "images/testapp99.png";

To show the app icon you can use the following XAML:

      <Image x:Name="ApplicationIcon" Source="{Binding AppIconSource, Source={StaticResource LocalizedStrings}}" />

Now we come to the second idea how to get different strings from the same resource file. The second solution employs an AppTitleConverter to replace occurencies of the simple app name with the Pro app name:

   public class AppTitleConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
return value.ToString().Replace(AppResources.ApplicationName, AppResources.ApplicationNamePro);
return value;
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
throw new NotImplementedException();

All you need are two strings for the app names, ApplicationName and ApplicationNamePro.

Then you can reference the app name in XAML as follows:

<local:AppTitleConverter x:Key="AppTitleConverter"/>
<TextBlock x:Name="ApplicationTitle" Text="{Binding LocalizedResources.ApplicationName, Converter={StaticResource AppTitleConverter}, Source={StaticResource LocalizedStrings}}" Style="{StaticResource PhoneTextNormalStyle}"/>

Tip.pngTip: You can use the same solutions to change more than the app name...


Two ways are shown how to use slightly different strings while maintaining sharing of resources between multiple versions of an app.

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

This page was last modified on 1 February 2014, at 17:08.
71 page views in the last 30 days.