使用XAML文件中的资源文件(Xamarin)

使用XAML文件中的资源文件(Xamarin)

问题描述:

如何在XAML(xamarin表单)中使用资源文件,如<Label Text="MyApp.resouces.MyString" />使用XAML文件中的资源文件(Xamarin)

有一个很好的文章here涉及这一话题。它包括很多例子。

后您实现您的TranslateExtension你的代码看起来就像这样:

<Label x:Name="lblName" Text="{local:TranslateExtension MyString}" /> 

你App.axml文件:

<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> 

然后您的标签:

<Label Text="{StaticResource AppName}"/>