Coder Social home page Coder Social logo

syncfusionexamples / how-to-customize-the-corner-radius-of-chipgroup-items-in-xamarin.forms Goto Github PK

View Code? Open in Web Editor NEW
0.0 5.0 1.0 519 KB

The sample aims to demonstrate various methods and approaches for customizing the corner radius of individual items within a ChipGroup in Xamarin.Forms.

C# 100.00%
chip chipgroup chips xamarin-forms chips-corner-radius xamarin-forms-chips

how-to-customize-the-corner-radius-of-chipgroup-items-in-xamarin.forms's Introduction

How to customize the corner radius of ChipGroup items in Xamarin.Forms

This demo explains the way to customize the corner radius in ChipGroup.

How to customize the corner radius of Chipgroup items in Xamarin

To set CornerRadius value for each chipgroup items in the Xamarin ChipGroup(SfChipGroup) by the following steps.

Step 1: Create a custom chipgroup class, which is derived from SfChipGroup , and define a property named CornerRadius.

C#:


public class CustomChipGroup : SfChipGroup
{
    public static readonly BindableProperty CornerRadiusProperty =
        BindableProperty.Create("CornerRadius", typeof(Thickness), typeof(CustomChipGroup), GetDefaultCornerRadius(), BindingMode.TwoWay, null, null);

    public Thickness CornerRadius
    {
        get { return (Thickness)GetValue(CornerRadiusProperty); }
        set { this.SetValue(CornerRadiusProperty, value); }
    }

    private static Thickness GetDefaultCornerRadius()
    {
        if (Device.RuntimePlatform == Device.Android)
        {
            return 40d;
        }

        return 15d;
    }
}

Step 2: Override the OnChildAdded method and hook the ChildAdded event in that method, which will be called whenever a new child is added to SfChipGroup. In that event method, you can set the value for CornerRadius for each individual SfChip.

C#:


public class CustomChipGroup : SfChipGroup
{
    . . .
    protected override void OnChildAdded(Element child)
    {
        base.OnChildAdded(child);
        child.ChildAdded += Child_ChildAdded;
    }

    private void Child_ChildAdded(object sender, ElementEventArgs e)
    {
        var sfChip = e.Element as SfChip;
        if (sfChip != null)
        {
            sfChip.SetBinding(SfChip.CornerRadiusProperty, new Binding() { Path = "CornerRadius", Source = this, Mode = BindingMode.TwoWay });
        }
    }
}

Step 3: Unhook the ChildAdded event in OnChildRemoved override method.

C#:


public class CustomChipGroup : SfChipGroup
{
    . . .
    protected override void OnChildRemoved(Element child)
    {
        child.ChildAdded -= Child_ChildAdded;
        base.OnChildRemoved(child);
    }
}

Step 4: Set the CornerRadius value for customized SfChipGroup.

XAML:


<local:CustomChipGroup ItemsSource="{Binding Items}" 
                                              DisplayMemberPath="Name"     
                                              CornerRadius="0"/>

Also refer our feature tour page to know more features available in our chips.

Troubleshooting

Path too long exception

If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.

how-to-customize-the-corner-radius-of-chipgroup-items-in-xamarin.forms's People

Contributors

mrhemalatha avatar ramya587 avatar sarubala20 avatar syncfusionbuild avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

mohanlalgo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.