Skip to content

Learn Mobile Development

Alamgeer's Blog

Menu
  • Home
  • Privacy Policy
Menu
Prevent Dark Mode in Xamarin forms

How to Prevent Dark Mode in Xamarin forms

Posted on February 3, 2023February 3, 2023 by Learn Mobile Development

When an app runs on iOS 13 and when a user flips to dark mode from settings then apps do not look so great. So there are two ways to handle this: either create different themes for Dark Mode and Light Mode and switch based on the system’s theme at runtime or prevent the Dark Mode. So In this article, I’m going to show you how to Prevent Dark Mode in Xamarin Forms.

Dark Mode is introduced in iOS 13 and In Android It’s introduced in Android 10 (API Level 29) in android it is called Dark Theme. 

Let’s Start

To force the light theme in application we need to do some changes in native side.

In iOS Side :

Add the following key to info.plist file :

<key>UIUserInterfaceStyle</key>
<string>Light</string>

We can also do this by creating custom renderer for either ContentPage or NavigationPage as follows :

Using ContentPage Renderer :

[assembly: ExportRenderer(typeof(ContentPage), typeof(CustomPageRenderer))]
namespace Example.iOS
{
    public class CustomPageRenderer : PageRenderer
    {
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            OverrideUserInterfaceStyle = UIUserInterfaceStyle.Light;
        }
    }
}

Using NavigationPage Renderer :

[assembly: ExportRenderer(typeof(NavigationPage), typeof(CustomNaviPageRenderer))]
namespace Example.iOS
{
    public class CustomNaviPageRenderer : NavigationRenderer
    {
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            OverrideUserInterfaceStyle = UIUserInterfaceStyle.Light;
        }
    }
}

In Android Side :

We have to put the below code to OnCreate() method in MainActivity :

AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;

That’s all for now!

Happy Coding! 😀

You may also like

get device and app informations in maui

How to get Device and App Informations in MAUI

UniformItemsLayout in MAUI

How to use UniformItemsLayout in MAUI

Post Views: 1,359
Share article with

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I'm Alamgeer Ashraf and having 11+ years of experience in enterprises mobile application development with Xamarin Native, Xamarin Forms & .Net MAUI.

Archives

  • February 2023 (1)
  • January 2023 (9)
  • December 2022 (5)
  • November 2022 (6)

Latest Posts

  • Prevent Dark Mode in Xamarin forms
    How to Prevent Dark Mode in Xamarin formsFebruary 3, 2023
  • apply color to Images
    How to apply color to Images and Icons in MAUIJanuary 30, 2023
  • iOS Large Page Title
    How to set iOS large page title in MAUIJanuary 26, 2023
  • Change StatusBar Color
    How to change StatusBar color in MAUIJanuary 22, 2023
  • Item reordering to CollectionView
    How to apply item reordering to CollectionView GridItemsLayout in MAUIJanuary 18, 2023

Popular Posts

  • How to apply color to Images and Icons in MAUI
  • How to use CollectionView as a GridItemLayout in Xamarin Forms
  • How to change StatusBar color in MAUI

Latest Comments

  1. knight online makro on Implementation Of Biometric Authentication in Xamarin FormsFebruary 12, 2026

    Your blog is always a highlight of my day

  2. dịch vụ backlink top.com vn on How to use CollectionView as a GridItemLayout in Xamarin FormsNovember 20, 2025

    Great post, you have pointed out some fantastic details , I besides think this s a very superb website.

  3. ryzen sunucu kirala on Implementation Of Biometric Authentication in Xamarin FormsNovember 4, 2025

    Thank you for sharing your personal experience and wisdom with us Your words are so encouraging and uplifting

  4. dofollow backlinks means on How to use FlexLayout in MAUIOctober 29, 2025

    Perfect piece of work you have done, this site is really cool with superb info .

  5. backlinks que es on How to use ObservableObject in MAUI for Data BindingOctober 28, 2025

    I like this internet site because so much useful stuff on here : D.

Our Visitor

0 0 8 9 3 2
Users Today : 2
Users Yesterday : 3
Users Last 7 days : 22
Users Last 30 days : 96
Users This Month : 2
Total views : 15357
How to use FlexLayout in MAUI
Trending
How to use FlexLayout in MAUI

Category

  • .Net MAUI
  • MAUI Community Toolkit
  • MVVM
  • Xamarin Community Toolkit
  • Xamarin Forms

Contact Me

  • LinkedIn
      © 2026 Learn Mobile Development