title: How to Check For Dark Mode in Xamarin.Forms
body: <p>Now that <a href="https://developer.apple.com/documentation/appkit/supporting_dark_mode_in_your_interface" rel="nofollow noreferrer">iOS 13</a> and <a href="https://developer.android.com/guide/topics/ui/look-and-feel/darktheme" rel="nofollow noreferrer">Android Q</a> allow the user to enable Dark Mode at the operating system level, how can I check for it in Xamarin.Forms?</p>
  
  <p>I've created this in my Xamarin.Forms project, but I'm not sure how to retrieve the values from Xamarin.iOS and Xamarin.Android.</p>
  
  <h3>IEnvironment.cs</h3>
  
  <pre class="lang-cs prettyprint-override"><code>using System.Threading.Tasks;
  
  namespace MyNamespace
  {
      public interface IEnvironment
      {
          Theme GetOperatingSystemTheme();
          Task&lt;Theme&gt; GetOperatingSystemThemeAsync();
      }
  
      public enum Theme { Light, Dark }
  }
  </code></pre>
  
  <h3>App.cs</h3>
  
  <pre class="lang-cs prettyprint-override"><code>using Xamarin.Forms;
  
  namespace MyNamespace
  {
      public App : Application
      {
          // ...
  
          protected override async void OnStart()
          {
              base.OnStart();
  
              Theme theme = DependencyService.Get&lt;IEnvironment&gt;().GetOperatingSystemTheme();
  
              SetTheme(theme);
          }
  
          protected override async void OnResume()
          {
              base.OnResume();
  
              Theme theme = DependencyService.Get&lt;IEnvironment&gt;().GetOperatingSystemTheme();
  
              SetTheme(theme);
          }
  
          void SetTheme(Theme theme)
          {
              //Handle Light Theme &amp; Dark Theme
          }
      }
  }
  </code></pre>