RatingBar Control- is a cross-platform plugin used for selecting the rating.
How To Use
Available on NuGet: https://www.nuget.org/packages/RatingBarControl/1.0.0
Install this Plugin in your Xamarin Form Project.
Install this Plugin in your Xamarin Form Project.
Namespace: xmlns:ratingbarcontrol="clr-namespace:RatingBarControl;assembly=RatingBarControl"
Implementation Example
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:ratingbarcontrol="clr-namespace:RatingBarControl;assembly=RatingBarControl" x:Class="TestApp.MainPage"> <StackLayout Margin="0,10,0,0" HorizontalOptions="Center" > <Label Text="{Binding Source={x:Reference rtControl},Path=SelectedStarValue,StringFormat='Seleced Star: {0}'}" /> <ratingbarcontrol:RatingBar StarHeightRequest="35" StarWidthRequest="35" EmptyStarImage="emptystar" FillStarImage="fillstar" x:Name="rtControl"/> </StackLayout> </ContentPage>
RatingBar Control Property
- StarHeightRequest: Used to set the Height of the Image.
- StarWidthRequest: Used to set the Width of the Image.
- EmptyStarImage: Specify the image name of the empty star.
- FillStarImage: Specify the image name of the filled star.
- SelectedStarCommand: Use this command to get the selected star value in ViewModel.
- SelectedStarValue: Used to set default selected star value.
- FlowDirection: Used to set the Rating Bar Control Flow Direction, either Left to Right or Right to left.
- Spacing: Used to set the Spacing between stars.
How to display the selected star rating
Write the Following code to display the selected star rating
<Label Text="{Binding Source={x:Reference rtControl},Path=SelectedStarValue,StringFormat='Seleced Star: {0}'}" / <ratingbarcontrol:RatingBar StarHeightRequest="35" StarWidthRequest="35" EmptyStarImage="emptystar" FillStarImage="fillstar" x:Name="rtControl"/>
How to get the selected rating
SelecedStarCommand: Use this command to get the selected star value in ViewModel.
Design Side:
<Label Text="{Binding SelectedStarValue,StringFormat='Selected Star is : {0}'}" /> <ratingbarcontrol:RatingBar StarHeightRequest="35" StarWidthRequest="35" EmptyStarImage="emptystar" FillStarImage="fillstar" SelectedStarCommand="{Binding SelectedStarCommand}" x:Name="rtControl"/>
Code Behind (ViewModel):
private int _selectedStarValue; public int SelectedStarValue { get => _selectedStarValue; set => SetProperty(ref _selectedStarValue, value); } public ICommand SelectedStarCommand => new Command<int>((selectedStarValue) => { SelectedStarValue = selectedStarValue; });