Dynamic RadShapeRating RadSegmentedControl with parameters

2 Answers 124 Views
Accessibility Rating SegmentedControl
XTZ
Top achievements
Rank 1
Iron
XTZ asked on 24 Jun 2021, 06:44 AM

Hello,

Using your RadShapeRating or RadSegmentedControl component, I have had the following problem.
I have a list of these components within a collectionView, they are generated dynamically and therefore I don't know how many of them I will have. How are these components designed to manage which of them has been clicked and therefore apply its value to the element of the list where it is located? Why they dont have a commandparameter like function, so we can pass across them a param like the id of the element of the list?

 

 

                <CollectionView Grid.Row="2" ItemsSource="{Binding ListaOpciones}" SelectionMode="None" x:Name="myList">
                    <CollectionView.ItemTemplate>
                        <DataTemplate>
                            <Grid BackgroundColor="#E8E8E8">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="2*" />
                                    <ColumnDefinition Width="3*" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Label Grid.Column="0" Text="{Binding opcion}" TextColor="Black" FontSize="17" Padding="15,5,5,2"></Label>

                                <telerikInput:RadShapeRating Grid.Column="1"  HeightRequest="30" WidthRequest="30" ItemsSpacing="6" 
                                                             ItemsCount="{Binding puntuacion}" VerticalOptions="Center"
                             ItemFill="LightGoldenrodYellow"
                             ItemStroke="Black"
                             SelectedItemFill="Yellow"
                             SelectedItemStroke="#efefef" />
                            </Grid>
                        </DataTemplate>
                    </CollectionView.ItemTemplate>
                </CollectionView>

I  want to achieve the next functionality: Every time a radShapeRating is rate i have to update the value of my "ListaOpciones<Options>"  element withe the value of  RadShapeRating.

Thanks for your help.

Regards.

2 Answers, 1 is accepted

Sort by
1
Yana
Telerik team
answered on 24 Jun 2021, 01:27 PM

Hello,

The CollectionView is bound to a collection of Options object, so each control inside the ItemTemplate has the Options instance as a binding context.  RadShapeRating provides Value property which specifies the selected items count, so basically you can bind with TwoWay binding that Value to the corresponding property of the Options object - in this way as soon as the user updates the rating, the property will be updated as well.

RadSegmentedControl exposes SelectedIndex property which in the same way can be bound to any of the used data item (Options in this case) properties.

I've attached a small example based on the provided snippet to show the exact approach, please download it and give it a try.

I hope I was of help.

Regards,
Yana
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
XTZ
Top achievements
Rank 1
Iron
answered on 25 Jun 2021, 11:50 AM

Hello Yana,

Thank you, it was exactly what I was looking for in both of them.

Regards.

Tags
Accessibility Rating SegmentedControl
Asked by
XTZ
Top achievements
Rank 1
Iron
Answers by
Yana
Telerik team
XTZ
Top achievements
Rank 1
Iron
Share this question
or