Telerik Forums
UI for Xamarin Forum
2 answers
90 views

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.

XTZ
Top achievements
Rank 1
Iron
 answered on 25 Jun 2021
3 answers
75 views

I am unable to retrieve the Value property of the RadShapeRating object in my xaml either by binding or by retrieving the value in my code behind after a button click event. Also, the ValueChanged event doesn't seem to fire. I'm also unable to look through the RadShapeRating children because the classes are protected. Here is my XAML:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" NavigationPage.HasNavigationBar="false" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Pages.AppointmentRatingPage" Title="Appointment Rating" xmlns:helpers="clr-namespace:Helpers;assembly=AssistForms" BackgroundImage="introbackground.png" xmlns:local="clr-namespace:AssistForms;assembly=AssistForms" xmlns:rating="clr-namespace:Telerik.XamarinForms.Input;assembly=Telerik.XamarinForms.Input" xmlns:userControls="clr-namespace:CustomControlls;assembly=AssistForms">
    <ContentPage.Resources>
        <ResourceDictionary>
        </ResourceDictionary>
    </ContentPage.Resources>
    <ContentPage.Content>
        <StackLayout Padding="30,100,30,70" HorizontalOptions="Center" VerticalOptions="Center">
            <Frame Padding="3" BackgroundColor="Gray">
                <StackLayout BackgroundColor="#D3D3D3">
                    <Image Source="mobilefit" Aspect="AspectFit" HeightRequest="35" HorizontalOptions="Start" Margin="5,5,0,0">
                    </Image>
                    <Grid>
                        <Image Source="introbackground.png" Aspect="AspectFill" />
                        <StackLayout VerticalOptions="FillAndExpand" Spacing="10" Padding="5,10,5,5">
                            <Label HorizontalTextAlignment="Center" FontSize="Large" VerticalOptions="Start">Rate your experience at the Y!</Label>
                            <Label HorizontalTextAlignment="Center" FontSize="15" TextColor="White" Text="{Binding Message}"/>
                            <Frame Margin="20,0,20,0">
                                <StackLayout Padding="20,20,20,50" HorizontalOptions="Center" VerticalOptions="Center" BackgroundColor="White" Spacing="30">
                                    <Label HorizontalOptions="Center" TextColor="#1E90FF" FontSize="18">Choose Your Rating</Label>
                                    <rating:RadShapeRating x:Name="rating" HorizontalOptions="Center"  Value="{Binding RatingValue, Mode=TwoWay}" ValueChanged="Handle_ValueChanged"  ></rating:RadShapeRating>

                                </StackLayout>
                            </Frame>
                            <StackLayout>
                                <Button Text="Don't Ask Again" TextColor="White" />
                                <StackLayout Orientation="Horizontal" VerticalOptions="Start">
                                    <Button Text="Cancel" HorizontalOptions="CenterAndExpand" TextColor="White" Command="{Binding CancelCommand}">
                                    </Button>
                                    <Button Text="Send" HorizontalOptions="CenterAndExpand" TextColor="White" FontAttributes="Bold" Clicked="Handle_Clicked">
                                    </Button>
                                </StackLayout>
                            </StackLayout>
                        </StackLayout>
                    </Grid>
                </StackLayout>
            </Frame>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

 

Here is my code behind:

using System;
using Xamarin.Forms;
using ViewModels;
using AssistForms;


namespace Pages
{
    public partial class AppointmentRatingPage : ContentPage
    {
        void Handle_ValueChanged(object sender, Xamarin.Forms.ValueChangedEventArgs e)
        {
            throw new NotImplementedException();
        }



        void Handle_Clicked(object sender, System.EventArgs e)
        {
            foreach (var child in rating.Children)
            {
                var childChild = child.BackgroundColor;
                //Telerik.XamarinForms.Input.RatingItem childRating = rating as Telerik.XamarinForms.Input.RatingItem;
                //  var backgroundCole = child.
                //RatingItem ratingItem = child as RatingItem;
            }
        }



        public string NavigationPageName { get; set; }


        public AppointmentRatingViewModel ViewModel
        {
            get;
            set;
        }



        public AppointmentRatingPage(AppointmentRating appointmentRating)
        {

            InitializeComponent();

            NavigationPage.SetHasNavigationBar(this, false);
            App.MasterDetailPageProperty.IsGestureEnabled = false;

            NavigationPageName = "AppointmentRating";

            ViewModel = new AppointmentRatingViewModel(appointmentRating);

            BindingContext = ViewModel;


        }



        protected override void OnAppearing()
        {
            base.OnAppearing();
        }

    }
}

 

Lance | Manager Technical Support
Telerik team
 answered on 14 Jun 2017
Top users last month
horváth
Top achievements
Rank 2
Iron
Iron
Steve
Top achievements
Rank 2
Iron
Erkki
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 2
Iron
Iron
Veteran
Jakub
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?