Reputation: 16764
I created two xamls (I created as ContentPage) one for Light theme and another for Dark theme (for iOS)
The LightTheme.xaml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LightTheme"/>
and LightTheme.xaml.cs
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace MyApp.Forms
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LightTheme : ResourceDictionary
{
}
}
Similar for DarkTheme.xaml(.cs).
In App.xaml.cs I put
public static void ApplyTheme()
{
if (AppInfo.RequestedTheme == AppTheme.Dark)
{
App.Current.Resources = new DarkTheme();
}
else
{
App.Current.Resources = new LightTheme();
}
}
and App.xaml
...
<ResourceDictionary Source="LightTheme.xaml">
<local:AppResource x:Key="AppResource"></local:AppResource>
<OnPlatform x:Key="validMargin" x:TypeArguments="Thickness" >
<On Platform="UWP" Value="0,-5,0,0"/>
</OnPlatform>
<!--The Colors-->
<Color x:Key="DarkPrimary">#403152</Color>
<Color x:Key="Primary">#564266</Color>
...
When build solution, I got errors
How to fix it ?
Upvotes: 1
Views: 245
Reputation: 14475
Check the scheme x:Class
in LightTheme.xaml , it should be namespace + class name ,modify as below
x:Class="Namespace.LightTheme"
Upvotes: 1