I am looking for an efficient way to style all my IPageDialogService usages in my .NET Maui app. Currently, I use the AppThemeBinding for all styling which are affected by light and dark modes. This works fine, but all my IPageDialogService references all still on a white background when using the dark mode.
In the official documentation isn't a dedicated styling part on the IPageDialogService. https://prismlibrary.com/docs/maui/dialogs/pagedialogs.html
It would be favorable to style the dialogs globally, all other styles are mostly in the styles.xaml file. Is there a specific TargetType for the IPageDialogService or a best practice for styling the dialogs?
Ok, turns out you can't style the dialogs via xaml. After some digging in the source code of prism and maui, we discovered, that in the end, the platform-specific dialogs are called and rendered; hence you must set the correct platform theme on theme switching in the app.
For Android the using AppCompatAlertDialog = AndroidX.AppCompat.App.AlertDialog;
is used.
#if ANDROID
AndroidX.AppCompat.App.AppCompatDelegate.DefaultNightMode = Current.UserAppTheme switch
{
AppTheme.Light => AndroidX.AppCompat.App.AppCompatDelegate.ModeNightNo,
AppTheme.Dark => AndroidX.AppCompat.App.AppCompatDelegate.ModeNightYes,
_ => AndroidX.AppCompat.App.AppCompatDelegate.ModeNightFollowSystem
};
#elif IOS
Platform.GetCurrentUIViewController().OverrideUserInterfaceStyle = Current.UserAppTheme switch
{
AppTheme.Light => UIKit.UIUserInterfaceStyle.Light,
AppTheme.Dark => UIKit.UIUserInterfaceStyle.Dark,
_ => UIKit.UIUserInterfaceStyle.Unspecified
};
#endif
Confirmed in this GitHub Issue: https://github.com/dotnet/maui/issues/6092