Computer Magic Logo
Static resource platform specific

Tuesday, April 26, 2016

Published by Aristotelis Pitaridis

We can define different values depending on the platform that the application is executed.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App1.Page1">
  <ContentPage.Resources>
    <ResourceDictionary>
      <OnPlatform x:Key="backgroundColor"                          
                  x:TypeArguments="Color"                         
                  Android="#404040" />
      <OnPlatform x:Key="textColor"                         
                  x:TypeArguments="Color"                         
                  Android="White"                         
                  WinPhone="Blue" />
    </ResourceDictionary>
  </ContentPage.Resources>
  <Label x:Name="MyLabel" 
         Text="Hello World!" 
         TextColor="{StaticResource Key=textColor}" 
         BackgroundColor="{StaticResource Key=backgroundColor}" />
</ContentPage>