Articles in this section

How to apply ripple background in .NET MAUI Radio Button?

Overview

In .NET MAUI applications, you can enhance the visual interaction of radio buttons by applying a ripple effect background. This article demonstrates how to apply a RippleBackground to the .NET MAUI Radio Button control using the .NET MAUI EffectsView control.

Custom Control Creation

To implement the ripple effect, create a custom control that inherits from SfRadioButton. Below is the code snippet for creating a custom RadioButton:

// Custom Control
#if ANDROID
public class CustomSfRadioButton : SfRadioButton, ITouchListener
#else
public class CustomSfRadioButton : SfRadioButton
#endif
{
    public CustomSfRadioButton()
    {
        
    }
#if ANDROID
    void ITouchListener.OnTouch(Syncfusion.Maui.Core.Internals.PointerEventArgs e)
    {                    
        var effects = this.Parent as SfEffectsView;
        if(e.Action == PointerActions.Pressed)
        {
            if (this.Parent is SfEffectsView)
            {
                effects?.OnTouch(e);
                this.IsChecked = true;
            }
        }
        else if(e.Action == PointerActions.Released)
        {
            if (this.Parent is SfEffectsView)
            {
                effects?.OnTouch(e);                   
            }
        }                                                                   
    }
#endif
}

XAML Implementation

After creating the custom control, use it within your XAML layout as shown below:

<ContentPage.Resources>
    <buttons:SfRadioGroupKey x:Key="radioButtonGroup"/>
</ContentPage.Resources>

<StackLayout Padding="10,0">
    <Label Text="Pizza Toppings:" FontAttributes="Bold"/>
    <VerticalStackLayout Padding="30,0">
        <core:SfEffectsView RippleBackground="Red">
            <local:CustomSfRadioButton Text="Pepperoni"  
                                       GroupKey="{StaticResource radioButtonGroup}" />
        </core:SfEffectsView>

        <core:SfEffectsView RippleBackground="Red">
            <local:CustomSfRadioButton Text="Chicken" 
                                       GroupKey="{StaticResource radioButtonGroup}"/>
        </core:SfEffectsView>

        <core:SfEffectsView RippleBackground="Red">
            <local:CustomSfRadioButton  Text="Mushrooms"  
                                        GroupKey="{StaticResource radioButtonGroup}"/>
        </core:SfEffectsView>

        <core:SfEffectsView RippleBackground="Red">
            <local:CustomSfRadioButton  Text="BBQ chicken pizza"  
                                        GroupKey="{StaticResource radioButtonGroup}"/>
        </core:SfEffectsView>
    </VerticalStackLayout>
</StackLayout>

By following the steps above, you can successfully apply a ripple effect background to the SfRadioButton in your .NET MAUI application, enhancing the user experience with a modern and interactive design.

Output

RadioButton.gif

Conclusion

Hope you enjoyed learning how to apply ripple background to the .NET MAUI Radio Button.

You can refer to our .NET MAUI Radio Button feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI Radio Button documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components from the License and downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Radio Button and other .NET MAUI components.

Please let us know in the following comments section if you have any queries or require clarifications. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied