Rating

in namespace DotVVM.BusinessPack.Controls

Renders a horizontal set of points representing a rating. If enabled, the user can select one of these points to set the rating.

Usage & Scenarios

Displays several stars (or any other symbols) and lets the user to select a some of them.

Sample 1: Basic Usage

The Value property represents a number of stars selected by the user.

The MaxValue specifies the number of stars to be displayed.

<bp:Rating Value="{value: Rating}"
           MaxValue="5" />
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Rating.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public double Rating { get; set; } = 4.5;
    }
}

Sample 2: Configuration

The AllowHalfPoints allows to select 1/2 of a star to be able to get more precise rating. By default, the user can select only the entire star.

The AllowPreviewOnHover property can be used to disable the hover effect that indicates which stars will be selected on click.

<bp:Rating Value="{value: Rating}"
           MaxValue="5"
           AllowHalfPoints="false"
           AllowPreviewOnHover="false" />
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Rating.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        public double Rating { get; set; } = 4;
    }
}

Sample 3: Changed Event

The Changed property specifies a command in the viewmodel that is triggered whenever the user changes the rating.

<bp:Rating Value="{value: Rating}"
           MaxValue="5"
           Changed="{command: RatingChanged()}" />

<p>Rating has changed {{value: ChangeCount}} times.</p>
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Rating.sample3
{
    public class ViewModel : DotvvmViewModelBase
    {
        public double Rating { get; set; } = 4.5;
        public int ChangeCount { get; set; }

        public void RatingChanged()
        {
            ChangeCount++;
        }
    }
}

Sample 4: Custom Icons

The icons in the control can be customized using the following properties:

  • EmptyPointIconCssClass represents an icon for a start that is not selected. The default value is fa fa-star (FontAwesome).
  • HalfPointIconCssClass represents an icon for a start that is partially selected. The default value is fa fa-star-half-empty (FontAwesome).
  • FullPointIconCssClass represents an icon for a start that is fully selected. The default value is fa fa-star0 (FontAwesome).
<bp:Rating Value="{value: Rating}"
           MaxValue="5"
           EmptyPointIconCssClass="empty"
           HalfPointIconCssClass="half"
           FullPointIconCssClass="full" />
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Rating.sample4
{
    public class ViewModel : DotvvmViewModelBase
    {
        public double Rating { get; set; } = 3.5;
    }
}

Properties

Name Type Description Notes Default Value
property icon AllowHalfPoints Boolean Gets or sets whether to display half points and allow the user to select half point values.
attribute
inner element
static value
bindable
default
True
property icon AllowPreviewOnHover Boolean Gets or sets whether to display a preview of the selected value when user hovers over the control.
attribute
inner element
static value
bindable
default
True
property icon Attributes Dictionary<String,Object>
attribute
inner element
static value
bindable
default
null
property icon ClientIDMode ClientIDMode Gets or sets the client ID generation algorithm.
attribute
inner element
static value
bindable
default
Static
property icon DataContext Object Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value.
attribute
inner element
static value
bindable
default
null
property icon EmptyPointIconCssClass String Gets or sets the CSS class used for empty points.
attribute
inner element
static value
bindable
default
fa fa-star-o
property icon Enabled Boolean Gets or sets whether the control responds to user actions.
attribute
inner element
static value
bindable
default
True
property icon FullPointIconCssClass String Gets or sets the CSS class used for full points.
attribute
inner element
static value
bindable
default
fa fa-star
property icon HalfPointIconCssClass String Gets or sets the CSS class used for half points.
attribute
inner element
static value
bindable
default
fa fa-star-half-empty
property icon ID String Gets or sets the unique control ID.
attribute
inner element
static value
bindable
default
null
property icon InnerText String Gets or sets the inner text of the HTML element.
attribute
inner element
static value
bindable
default
null
property icon MaxValue Int32 Gets or sets the maximum value that the Value can reach.
attribute
inner element
static value
bindable
default
5
property icon Value Double? Gets or sets the current value of the Rating.
attribute
inner element
static value
bindable
default
null
property icon Visible Boolean Gets or sets whether the control is visible.
attribute
inner element
static value
bindable
default
True

Events

Name Type Description
event icon Changed Command Gets or sets the command that is called when Value changes.

HTML produced by the control