Global Resources in Xamarin.Forms

First, when I checked Google, all I could find was articles saying this can’t be done.  Humbug.  Thanks to Roger Peters and jFarrell I got it done (well, they did and then I did, but now you will).

Here are the steps (and they are pretty easy)

  • Create a normal XAML file named App.xaml.
  • This will automatically create a file named App.xaml.cs
  • Copy from App.cs to App.xaml.cs and delete App.cs
  • In App.xaml set the ContentPage to be an Application and create a resource dictionary
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="eSiteMoble.App">
 
 
  <Application.Resources>
    <ResourceDictionary>
  • Add the keyword Partial before class in App.xaml.cs
  • Add InitializeComponent to the constructor (this is critical)

Hey! Presto! your resources are available to any page…

<Label Text="Remember Me?"
             TextColor="{StaticResource TextForegroundColor}"

Easy as cake. Piece of Pie.

About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET will be released early in 2025. Liberty is a Senior SW Engineer for CNH and he was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Microsoft MVP.
This entry was posted in Xamarin. Bookmark the permalink.

One Response to Global Resources in Xamarin.Forms

Comments are closed.