Coder Social home page Coder Social logo

syncfusionexamples / how-to-select-multiple-chips-from-the-.net-maui-sfchipgroup Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 335 KB

The sample demonstrates how to enable and select multiple chips from the .NET MAUI ChipGroup [SfChipGroup].

C# 100.00%
chipgroup chips maui maui-chip select-chips

how-to-select-multiple-chips-from-the-.net-maui-sfchipgroup's Introduction

How-to-select-multiple-chips-from-the-.NET-MAUI-SfChipGroup

This sample demonstrates how to enable the selection of multiple chips within a .NET MAUI ChipGroup (SfChipGroup) control. By setting the ChipType to Filter and utilizing visual states, you can select multiple chips and change the selected chip’s color. Additionally, learn how to programmatically select chips using the SelectedItem property

Consider a scenario where you need to allow users to select multiple languages from a provided list.

Steps:

Step 1: Set ChipType to Filter for Multiple Selection

To enable the selection of multiple chips in a group, set the ChipType property of the SfChipGroup to “Filter”. This configuration allows users to choose more than one chip within the group.

XAML

<chip:SfChipGroup ChipType="Filter"> ... </chip:SfChipGroup>

Step 2: Add Visual States for Selected Chip Color

Utilize visual states to dynamically change the selected chip’s color when chips are clicked. Customize the ChipBackground and ChipTextColor properties for the selected and unselected states.

XAML

<chip:SfChipGroup ChipType="Filter"
                  ItemsSource="{Binding Languages}"
                  SelectionIndicatorColor="White"
                  SelectedItem="{Binding SelectedItems}"
                  DisplayMemberPath="Name">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal">
                    <VisualState.Setters>
                        <Setter Property="ChipTextColor" Value="Black" />
                        <Setter Property="ChipBackground" Value="LightGray" />
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="Selected">
                    <VisualState.Setters>
                        <Setter Property="ChipTextColor" Value="White" />
                        <Setter Property="ChipBackground" Value="Red" />
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
 </chip:SfChipGroup>

Step 3: Programmatically Select Chips

In your ViewModel class, populate the required list of chip items and predefined selected items.

C#

public class ViewModel
{

    public ObservableCollection<Language> Languages { get; set; }

    public ObservableCollection<Language> SelectedItems { get; set; }

    public ViewModel()
    {
        this.Languages = new ObservableCollection<Language>();

        Languages.Add(new Language() { Name = "C#" });
        Languages.Add(new Language() { Name = "Python" });
        Languages.Add(new Language() { Name = "Java" });
        Languages.Add(new Language() { Name = "Js" });

        SelectedItems = new ObservableCollection<Language>() { Languages[0], Languages[1] };
    }
    
}

how-to-select-multiple-chips-from-the-.net-maui-sfchipgroup's People

Contributors

arunachalam13 avatar arunachalam3641 avatar edberg-vasan avatar naveenkumar-sanjeevirayan avatar sarubala20 avatar syncfusionbuild avatar

Watchers

 avatar  avatar  avatar

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.