.net MAUI RadComboBox Multiple Selection to command

1 Answer 75 Views
ComboBox
Jeys
Top achievements
Rank 1
Jeys asked on 02 Nov 2023, 06:44 AM

<telerik:RadComboBox.Behaviors>
                                    <mct:EventToCommandBehavior EventName="SelectionChanged"
                                                                Command="{Binding }"
                                                                CommandParameter=""
                                </telerik:RadComboBox.Behaviors>

 

Is it possible to map the SelectionChanged event to command with added and removed items as parameters?

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 06 Nov 2023, 10:36 AM

Hello Jeys,

You can use the EventArgsConverter property of the EventToCommandBehavior to get the ComboBoxSelectionChanged args, here is a quick example:

<telerik:RadComboBox ItemsSource="{Binding Items}" 
                    DisplayMemberPath="Population"
                    x:Name="boundComboBox">
    <telerik:RadComboBox.Behaviors>
        <mct:EventToCommandBehavior EventName="SelectionChanged" x:Name="myBehavior"
                                Command="{Binding SelectionChangedCommand}"
                                EventArgsConverter="{StaticResource SelectionChangedEventArgsConverter}" />
    </telerik:RadComboBox.Behaviors>
</telerik:RadComboBox>

The SelectionChangedEventArgsConverter can be used just to pass the args values:

public class SelectionChangedEventArgsConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {

        return value;
    }
}

Then in the SelectionChangedCommand Execute method you can take the added and removed items:

private void SelectionChangedExecute(object param)
{
    var selectionEventArgs = param as Telerik.Maui.Controls.ComboBoxSelectionChangedEventArgs;
    if (selectionEventArgs != null)
    {
        var addedItems = selectionEventArgs.AddedItems;
        var removedItems = selectionEventArgs.RemovedItems;
    }
}

Please give it a try and let me know how it goes.

Regards,
Yana
Progress Telerik

A brand new .NET MAUI course was just added to the Virtual Classroom. The training course is developed to help you get started with the Telerik UI for .NET MAUI components and features. It aims to put you in the shoes of an engineer who adds new features to an existing application. You can check it out at https://learn.telerik.com
Tags
ComboBox
Asked by
Jeys
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or