WinUI

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class SfRating

    Show / Hide Table of Contents

    Class SfRating

    The SfRating control allows the user to rate the items from the available predefined number of items.

    Inheritance
    System.Object
    SfRating
    Namespace: Syncfusion.UI.Xaml.Editors
    Assembly: Syncfusion.Editors.WinUI.dll
    Syntax
    public class SfRating : Control
    Examples

    This example illustrates how to set the items using Items .

    <syncfusion:SfRating>
    <syncfusion:SfRating.Items>
        <syncfusion:SfRatingItem/>
        <syncfusion:SfRatingItem/>
        <syncfusion:SfRatingItem/>
        <syncfusion:SfRatingItem/>
        <syncfusion:SfRatingItem/>
    </syncfusion:SfRating.Items>
    </syncfusion:SfRating>

    This example illustrates how to set the items using ItemsCount.

    <syncfusion:SfRating ItemsCount="5">
    </syncfusion:SfRating>  

    Constructors

    SfRating()

    Initializes a new instance of the SfRating class.

    Declaration
    public SfRating()

    Fields

    EnableToolTipProperty

    Identifies EnableToolTip dependency property.

    Declaration
    public static readonly DependencyProperty EnableToolTipProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the EnableToolTip dependency property.

    IsClearEnabledProperty

    Identifies IsClearEnabled dependency property.

    Declaration
    public static readonly DependencyProperty IsClearEnabledProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The Identifier for the IsClearEnabled dependency property.

    IsReadOnlyProperty

    Identifies IsReadOnly dependency property.

    Declaration
    public static readonly DependencyProperty IsReadOnlyProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the IsReadOnly dependency property.

    ItemsCountProperty

    Identifies ItemsCount dependency property.

    Declaration
    public static readonly DependencyProperty ItemsCountProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The Identifier for the ItemsCount dependency property.

    ItemSizeProperty

    Identifies ItemSize dependency property.

    Declaration
    public static readonly DependencyProperty ItemSizeProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the ItemSize dependency property.

    ItemTemplateSelectorProperty

    Identifies ItemTemplateSelector dependency property.

    Declaration
    public static readonly DependencyProperty ItemTemplateSelectorProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the ItemTemplateSelector dependency property.

    OrientationProperty

    Identifies Orientation dependency property.

    Declaration
    public static readonly DependencyProperty OrientationProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The Identifier for the Orientation dependency property.

    PlaceholderValueProperty

    Identifies PlaceholderValue dependency property.

    Declaration
    public static readonly DependencyProperty PlaceholderValueProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The Identifier for the PlaceholderValue dependency property.

    PrecisionProperty

    Identifies Precision dependency property.

    Declaration
    public static readonly DependencyProperty PrecisionProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the Precision dependency property.

    RatedItemStyleProperty

    Identifies RatedItemStyle dependency property.

    Declaration
    public static readonly DependencyProperty RatedItemStyleProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the RatedItemStyle dependency property.

    ToolTipFormatProperty

    Identifies ToolTipFormat dependency property.

    Declaration
    public static readonly DependencyProperty ToolTipFormatProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the ToolTipFormat dependency property.

    UnratedItemStyleProperty

    Identifies UnratedItemStyle dependency property.

    Declaration
    public static readonly DependencyProperty UnratedItemStyleProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the UnratedItemStyle dependency property.

    ValueProperty

    Identifies Value dependency property.

    Declaration
    public static readonly DependencyProperty ValueProperty
    Field Value
    Type Description
    Microsoft.UI.Xaml.DependencyProperty

    The identifier for the Value dependency property.

    Properties

    EnableToolTip

    Gets or sets a value indicating whether SfRating shows tooltip content.

    Declaration
    public bool EnableToolTip { get; set; }
    Property Value
    Type Description
    System.Boolean

    It takes the boolean value. The default value is false, which indicates that control will not show tooltip content.

    IsClearEnabled

    Gets or sets a value that determines whether a user can remove their rating or not.

    Declaration
    public bool IsClearEnabled { get; set; }
    Property Value
    Type Description
    System.Boolean

    It takes a boolean value.The default value is true, which indicates that user can remove their rating value by default.

    IsReadOnly

    Gets or sets the value indicates whether user is allowed to edit the rating value.

    Declaration
    public bool IsReadOnly { get; set; }
    Property Value
    Type Description
    System.Boolean

    It takes the boolean value. The default value is false, which indicates that control is not read only mode.

    Items

    Gets the collection to generate the rating items for the rating control.

    Declaration
    public ObservableCollection<SfRatingItem> Items { get; }
    Property Value
    Type Description
    System.Collections.ObjectModel.ObservableCollection<SfRatingItem>

    A collection that is used to generate the content of the SfRating. The default value is null.

    Examples

    The following example shows how to define a Items in SfRating.

    <syncfusion:SfRating>
       <syncfusion:SfRating.Items>
           <syncfusion:SfRatingItem/>
           <syncfusion:SfRatingItem/>
           <syncfusion:SfRatingItem/>
           <syncfusion:SfRatingItem/>
           <syncfusion:SfRatingItem/>
      </syncfusion:SfRating.Items>
    </syncfusion:SfRating>   

    ItemsCount

    Gets or sets value that determines the count of rating item in the rating control.

    Declaration
    public int ItemsCount { get; set; }
    Property Value
    Type Description
    System.Int32

    It takes the integer value that represents number of items manually added. The default value is 0, which indicates that items not added manually.

    Remarks

    When both the Items and the ItemsCount properties are set, the Items property takes precedence.

    ItemSize

    Gets or sets the value for the size of each rating item in the rating control.

    Declaration
    public double ItemSize { get; set; }
    Property Value
    Type Description
    System.Double

    It takes the double value. The default value is 50, which indicates that item size is 50 default.

    ItemTemplateSelector

    Gets or sets the custom view for rating items.

    Declaration
    public DataTemplateSelector ItemTemplateSelector { get; set; }
    Property Value
    Type Description
    Microsoft.UI.Xaml.Controls.DataTemplateSelector

    A custom Microsoft.UI.Xaml.Controls.DataTemplateSelector object that provides logic and returns a Microsoft.UI.Xaml.DataTemplate. The default value is null.

    Examples
    <Grid.Resources>
      <DataTemplate x:Key="selectedtemplate">
         <Viewbox>
             <StackPanel Orientation = "Vertical" >
                  <Image Source="Assets/Rating/AngrySelected.png"/>
             </StackPanel>
         </Viewbox>
       </DataTemplate>
       <DataTemplate x:Key="unSelectedTemplate">
         <Viewbox>
             <StackPanel Orientation = "Vertical" >
                  <Image Source="Assets/Rating/AngryUnSelected.png"/>
             </StackPanel>
         </Viewbox>
       </DataTemplate>
       <local:ContentTemplateSelector x:Key="templateselector" 
                                   SelectedTemplate="{StaticResource selectedtemplate}" 
                                   UnSelectedTemplate="{StaticResource unSelectedTemplate}"/>
    </Grid.Resources>
    <syncfusion:SfRating Name="ratingControl" 
                        Items="{Binding RatingItems}"
                        TemplateSelector="{StaticResource templateselector}" />
    class ContentTemplateSelector : DataTemplateSelector
    {
       public DataTemplate SelectedTemplate { get; set; }
       public DataTemplate UnSelectedTemplate { get; set; }
       protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
       {
           if (container == null)
               return null;
           SfRating Rating = container as SfRating;
           if (Rating.Items.IndexOf((SfRatingItem) item) + 1 <= Rating.Value)
               return SelectedTemplate;
           return UnSelectedTemplate;
       }
    }

    Orientation

    Gets or sets the value indicates whether the rating items are arranged either vertically or horizontally.

    Declaration
    public Orientation Orientation { get; set; }
    Property Value
    Type Description
    Microsoft.UI.Xaml.Controls.Orientation

    Specifies the one of the enumeration values that sets the orientation of rating items. The default is Horizontal.

    PlaceholderValue

    Gets or sets the average rating for the control until the value is changed by a user or other action.

    Declaration
    public double PlaceholderValue { get; set; }
    Property Value
    Type Description
    System.Double

    It takes the double value. The default value is 0.

    Precision

    Gets or sets the value for precision mode to set accuracy level of rating. 

    Declaration
    public RatingPrecision Precision { get; set; }
    Property Value
    Type Description
    RatingPrecision
    Examples
    <syncfusion:SfRating Precision="Half"/>

    RatedItemStyle

    Gets or sets the style for the selected items in the rating control.

    Declaration
    public Style RatedItemStyle { get; set; }
    Property Value
    Type Description
    Microsoft.UI.Xaml.Style

    The style that defines the appearance of rated item in SfRating. The default value is null.

    Examples
    <Grid.Resources>
       <Style TargetType="Path" x:Key="ratedStyle">
             <Setter Property = "Fill" Value="Yellow" />
              <Setter Property = "Stroke" Value="Gray"/>
              <Setter Property = "StrokeThickness" Value="2"/>
          </Style>
    </Grid.Resources>
    
    <syncfusion:SfRating ItemsCount="5"
                         RatedItemStyle="{StaticResource ratedStyle}">
    </syncfusion:SfRating>   

    ToolTipFormat

    Gets or sets a value of tooltip format which shows the custom content of tooltip.

    Declaration
    public string ToolTipFormat { get; set; }
    Property Value
    Type Description
    System.String

    Custom numeric format strings and Standard numeric format strings can be used to format the tooltip content.

    UnratedItemStyle

    Gets or sets the style for the unselected items in the rating control.

    Declaration
    public Style UnratedItemStyle { get; set; }
    Property Value
    Type Description
    Microsoft.UI.Xaml.Style

    The style that defines the appearance of unrated item in SfRating. The default value is null.

    Examples
    <Grid.Resources>
       <Style TargetType="Path" x:Key="unratedStyle">
             <Setter Property = "Fill" Value="Black" />
              <Setter Property = "Stroke" Value="Blue"/>
              <Setter Property = "StrokeThickness" Value="2"/>
          </Style>
    </Grid.Resources>
    
    <syncfusion:SfRating ItemsCount="5"
            UnratedItemStyle="{StaticResource unratedStyle}">
    </syncfusion:SfRating>   

    Value

    Gets or sets the current value of the rating control.

    Declaration
    public double Value { get; set; }
    Property Value
    Type Description
    System.Double

    It takes the double value. The default value is 0, which indicates that no item is rated.

    Methods

    OnApplyTemplate()

    Build the visual tree for the SfRating class.

    Declaration
    protected override void OnApplyTemplate()

    OnCreateAutomationPeer()

    Returns a class-specific AutomationPeer Implementations for the Microsoft UI Automation infrasturcutre.

    Declaration
    protected override AutomationPeer OnCreateAutomationPeer()
    Returns
    Type Description
    Microsoft.UI.Xaml.Automation.Peers.AutomationPeer

    The class-specific AutomationPeer subclass.

    OnKeyDown(KeyRoutedEventArgs)

    Invoked when the KeyDown attached event reaches an element in its route that is derived from this class. Override this method to update the rating value via keyboard navigation using arrow keys.

    Declaration
    protected override void OnKeyDown(KeyRoutedEventArgs e)
    Parameters
    Type Name Description
    Microsoft.UI.Xaml.Input.KeyRoutedEventArgs e

    The Microsoft.UI.Xaml.Input.KeyRoutedEventArgs that contains the event data.

    OnPointerExited(PointerRoutedEventArgs)

    Occurs when pointer is exited from the rating.

    Declaration
    protected override void OnPointerExited(PointerRoutedEventArgs e)
    Parameters
    Type Name Description
    Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e

    The Microsoft.UI.Xaml.Input.PointerRoutedEventArgs that contains the event data.

    Events

    ValueChanged

    Occurs when the value changed in the SfRating control.

    Declaration
    public event EventHandler<RatingValueChangedEventArgs> ValueChanged
    Event Type
    Type Description
    System.EventHandler<RatingValueChangedEventArgs>
    Back to top Generated by DocFX
    Copyright © 2001 - 2023 Syncfusion Inc. All Rights Reserved