A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Use theming and AppThemeBinding (or the SetAppTheme extensions) so the RadioButton visuals react when the system theme changes, instead of staying with the colors they had when first rendered.
There are two parts to solve:
- Unselected circles staying black/white when theme changes
Define light/dark colors in resources and bind them viaAppThemeBinding, or useSetAppThemeColorin code. For example, if using a customControlTemplateforRadioButton:<ContentPage.Resources> <Color x:Key="RadioStrokeLight">Black</Color> <Color x:Key="RadioStrokeDark">White</Color> <Style TargetType="RadioButton"> <Setter Property="ControlTemplate"> <Setter.Value> <ControlTemplate> <Border> <Grid> <Ellipse Stroke="{AppThemeBinding Light={StaticResource RadioStrokeLight}, Dark={StaticResource RadioStrokeDark}}" StrokeThickness="2" /> <!-- inner dot, etc. --> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </ContentPage.Resources>AppThemeBindingensures the stroke color updates immediately when the system theme switches, instead of remaining the original black/white. This is the same mechanism used for labels and images that change with the theme:
If the template is created in C#, use<Label TextColor="{AppThemeBinding Light=Green, Dark=Red}" />SetAppThemeColoron theEllipse.Stroke(or equivalent property) so it responds to theme changes. - Selected indicator always blue and not suitable for dark theme
Redefine theRadioButtonappearance with aControlTemplateand theme-aware visual states. For example, in the template’sVisualStateManagerfor theCheckedstate, bind the fill/stroke of the inner circle to theme-specific resources usingAppThemeBindingorSetAppThemeColor. That way the selected color can be, for example, blue in light theme and a lighter accent in dark theme. .NET MAUIRadioButtonis aTemplatedView, so a customControlTemplatecan fully control the visual structure and colors, and the template can use theme-aware resources.
If the default wizard-generated style is not theme-aware, replace it with a ControlTemplate-based style that uses AppThemeBinding or SetAppThemeColor for all colors that must change between light and dark.
References: