Dark mode on Xamarin
Dark mode darkens background colours and provides a more comfortable viewing experience in low light. This is essential for many visually impaired people since a light background colour can be painful or even impossible to look at for an extended period of time. But also people who have problems with their concentration, for example due to a brain disorder, benefit greatly from dark mode.
With Xamarin, you can detect dark mode by checking if the RequestedTheme
property equals OSAppTheme.Dark
.
In XAML
you can use AppThemeBinding
to define different resources for dark mode.
using Xamarin.Essentials;
OSAppTheme theme = Application.Current.RequestedTheme;
if (theme == OSAppTheme.Dark) {
// Dark mode
}