I need to change the color of a RadButton highlight when it's pressed. It's currently a Grey and I need it to be white. I understand theming, but can't find any documentation on what Color x:key values can be set for the RadButton.
Any help will be greatly appreciated.
3 Answers, 1 is accepted
You can use the Pressed and Released event handlers to accomplish that. Here's an example:
<
telerikInput:RadButton
Text
=
"Press Me"
BackgroundColor
=
"White"
TextColor
=
"DarkRed"
BorderColor
=
"DarkRed"
BorderThickness
=
"2"
WidthRequest
=
"100"
HeightRequest
=
"45"
VerticalOptions
=
"Center"
HorizontalOptions
=
"Center"
Pressed
=
"Button_OnPressed"
Released
=
"Button_OnReleased"
/>
private
void
Button_OnPressed(
object
sender, EventArgs e)
{
if
(sender
is
RadButton btn)
{
btn.BackgroundColor = Color.DarkRed;
btn.TextColor = Color.White;
}
}
private
void
Button_OnReleased(
object
sender, EventArgs e)
{
if
(sender
is
RadButton btn)
{
btn.BackgroundColor = Color.White;
btn.TextColor = Color.DarkRed;
}
}
Native Approach
If this is not sufficient or you need to change other styles that are not available in the Xamarin.Forms API layer (i.e. hover), you will will to write a custom Renderer to override the native styling. In case you want/need to do this, the renderer class to override is Telerik.XamarinForms.InputRenderer.[platform].ButtonRenderer.
Regards,
Lance | Technical Support Engineer, Principal
Progress Telerik
Hi Lance, thank you for your reply. I thought of the above Button_OnPressed approach first, and it would be perfect, but it didn't work for me. I tried again after your response, and I found that it will work for any color except for White(which is the background color assigned to this button in xaml) If I set the background to Color.White, or Color.FromHex("#FFFFFF") the highlight is still Gray. Any other color appears to work as you explain above. This seems like a bug to me. I'm using version 2019.2.513.1
It would be nice if this were a parameter "PressedHighlightColor" or styleable.
This could be due to the native platform setting the styling that Xamarin.Forms doesn't override. In order for me to assist further, I'll need to know more about the application.
- What version of Xamarin.Forms are you using? (if it's XF 4.x, please update to the latest UI for Xamarin release 2019.2.619)
- What are the target platform specifics? (the platform this is happening on and details like SDK and package dependencies).
Note: At your request, I can convert this to a Support Ticket because you have a Support License with your trial. You can attach a project to a ticket as well as fill in the platform details in a support Ticket.
Regards,
Lance | Technical Support Engineer, Principal
Progress Telerik