Monday, 30 July 2018

Learning Resources

Step1: TranslateExtension.cs

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Text;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace NewResourceLearning.Helpers.Resources
{
[ContentProperty("Text")]
public class TranslateExtension : IMarkupExtension
{
const string ResourceId = "NewResourceLearning.Helpers.Resources.AppResources";
public string Text { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Text == null)
return null;
ResourceManager resourceManager = new ResourceManager(ResourceId, typeof(TranslateExtension).GetTypeInfo().Assembly);
return resourceManager.GetString(Text, CultureInfo.CurrentCulture);
}
}
}
Step2:MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:NewResourceLearning"
xmlns:res="clr-namespace:NewResourceLearning.Helpers.Resources"
x:Class="NewResourceLearning.MainPage">
<StackLayout>
<Label Text="{res:Translate Mystringcall1}" FontSize="Medium" TextColor="Black"
VerticalOptions="CenterAndExpand"
VerticalTextAlignment="Center"
Margin="20,0"
HorizontalOptions="FillAndExpand"
HorizontalTextAlignment="Start"/>
<Label Text="{res:Translate Mystringcall2}" FontSize="Medium" TextColor="Black"
VerticalOptions="CenterAndExpand"
VerticalTextAlignment="Center"
Margin="20,0"
HorizontalOptions="FillAndExpand"
HorizontalTextAlignment="Start"/>
</StackLayout>
</ContentPage>
view raw MainPage.xaml hosted with ❤ by GitHub

No comments:

Post a Comment