Skip to content

RadioButton Background does not reset when set to null at runtime #34993

Description

@Shalini-Ashokan

Description

When the Background property of a RadioButton is set to a custom color or gradient and then changed to null at runtime, the background does not reset to the default transparent state. The previously applied background persists visually.

Android: Dynamic changes from gradient to background color are not working.
Windows: The gradient is not working, and dynamic changes to a null background are also not working.

Steps to Reproduce

  1. Create a RadioButton with a solid or gradient Background
    2. Add a button that sets radioButton.Background = null; on click
    3. Run on Windows
    Tap the button

Expected Behavior
The RadioButton gradient must be apply and background should become transparent when we set to null(default native appearance) after setting Background = null.

xaml

<StackLayout Margin="20"
                     Spacing="20">
                <RadioButton x:Name="radioButton"
                             Content="Option 1"/>
                <Button Text="Set Background to Red"
                        Clicked="OnSetRedBackgroundClicked"/>
                <Button Text="Set Background to null"
                        Clicked="OnButtonClicked"
                        x:Name="button"
                        Padding="10"/>
                <Button Text="Set Background (Gredient)"
                        Clicked="OnSetBackgroundClicked"
                        x:Name="setBackgroundButton"
                        Padding="10"/>
        </StackLayout>

xaml.cs

void OnSetBackgroundClicked(object sender, EventArgs e)
	{
		radioButton.Background = new LinearGradientBrush(
			new GradientStopCollection
			{
				new GradientStop { Color = Colors.Red, Offset = 0.0f },
				new GradientStop { Color = Colors.Blue, Offset = 1.0f }
			},
			new Point(0, 0),
			new Point(1, 1)
		);
	}
	void OnButtonClicked(object sender, EventArgs e)
	{
		radioButton.Background = null;
	}

	void OnSetRedBackgroundClicked(object sender, EventArgs e)
	{
		radioButton.Background = new SolidColorBrush(Colors.Red);
	}

Link to public reproduction project repository

No response

Version with bug

10.0.50

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows, Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions