I have:
C#
In the xaml.cs code I tried:
C#
gRBuEradicatedBlueCities.Background = #ffffff;which does not work.
How do I programmatically change a RadioButton Background?
I have:
In the xaml.cs code I tried:
gRBuEradicatedBlueCities.Background = #ffffff;which does not work.
How do I programmatically change a RadioButton Background?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted May 20, 2025, 1:05 AM EDT
To programmatically change the Background of a RadioButton, you need to assign a Brush object, not a raw color string.
gRBuEradicatedBlueCities.Background = new SolidColorBrush(Colors.White); // OR gRBuEradicatedBlueCities.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#ffffff"));Blocked AccountRank #403 · 6.2K reputationPosted May 20, 2025, 8:03 AM EDT
You can’t directly assign a color code like
#ffffffto change the background in C#. Instead, you need to use aBrushobject as Amit suggested. For example, to set the background to white, you can write: