Monday, February 06, 2012

WP7–using Application.Resources to define string resources

Scenario: You need to define a string value that needs to be reused across your application (eg: Application Title)

One way the above scenario can be implemented is by using the “Application.Resources” in the App.Xaml file.

The first step is to define the string resource. This is done by defining the type (clr:String) and a key that will be used to access the string. The value is also defined here:

        <clr:String x:Key="ApplicationTitle">OptiRoute</clr:String>

The above resource can then be accessed in your XAML markup using StaticResource markup extension:

<TextBlock x:Name="ApplicationTitle" Text="{StaticResource ApplicationTitle}" Style="{StaticResource PhoneTextNormalStyle}"/>

No comments: