Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

xamarin form - label stringformat in resourcefile

ManhaoChenManhaoChen NZMember ✭✭
edited October 2016 in Xamarin.Forms

is it possible to have the format string in a resource file like the following?

<Label x:Name="lblName" Text="{Binding GivenName, StringFormat='x:Static resx:AppResources.lbl_format'}" Style="{StaticResource PersonalDetailsLblName}" />

<data name="lbl_format" xml:space="preserve"> <value>Hi {0}</value> </data>
my expected label text is 'Hi '

but what i get when running emulator the label text = x:Static resx:AppResources.lbl_format

Best Answers


  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Yes you can put string formatting as a resource. I do it as follows (NOT in the app.resx though, but it should be basically the same):

    On the page:

                            <Label BindingContext="{x:Reference this}"
                                   Text="{Binding GpsLastValid.Latitude,
                                                  StringFormat={StaticResource formatdecimalfourplaces}}">

    then the resource as:

                <x:String x:Key="formatdecimalfourplaces">{0:0.0000}</x:String>
  • ManhaoChenManhaoChen NZMember ✭✭

    ah, the reason i wanting to put it into resource is due to globalization

    there will be some instances where i'll have to use eg $100 vs ¥100 (this is just an example)

    <data name="lbl_currency_format" xml:space="preserve"> <value>${0}</value> </data>

    <data name="lbl_currency_format" xml:space="preserve"> <value>¥{0}</value> </data>

Sign In or Register to comment.