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.
One Response to Global Resources in Xamarin.Forms