Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use resource file in XAML file (Xamarin)

How to use resource files in XAML (xamarin forms) like <Label Text="MyApp.resouces.MyString" />?

like image 643
Marco Antonio Quintal Avatar asked Oct 18 '25 14:10

Marco Antonio Quintal


2 Answers

There is a nice article here covering this topic. It includes lot of examples.

After you implement your TranslateExtension your code will look like this:

<Label x:Name="lblName" Text="{local:TranslateExtension MyString}" />
like image 124
Jan Nepraš Avatar answered Oct 22 '25 00:10

Jan Nepraš


Your App.axml file:

<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Master.App">
    <Application.Resources>
        <!-- Application resource dictionary -->
        <ResourceDictionary>
            <x:String x:Key="AppName">Name of app</x:String>
        </ResourceDictionary>
    </Application.Resources>
</Application>

And then your label:

<Label Text="{StaticResource AppName}"/>
like image 23
hericson Avatar answered Oct 22 '25 02:10

hericson