Category / Section
How to prevent user interaction with WinRT Rating?
3 mins read
To prevent the interaction with the SfRating control, set IsReadOnly property to true. When this property is enabled, we could not able to rate the SfRatingItem. But it allows to perform interactions with tooltip and PointerOverFill when precision is changed. In order to prevent this interactions, set ShowTooltip to false and colors for PointerOverFill and PointerOverStroke.
Prevent Mouse interactions with the control by setting IsHitTestVisible property as false
The same has been explained in the following code example
XAML
<Input:SfRating Value="2" ItemsCount="5" HorizontalAlignment="Center" VerticalAlignment="Center" Precision="Exact" Foreground="Yellow" ShowToolTip="False" IsReadOnly="True"> <Input:SfRating.ItemContainerStyle> <Style TargetType="Input:SfRatingItem"> <Setter Property="Height" Value="40"/> <Setter Property="Width" Value="40"/> <Setter Property="RatedFill" Value="Yellow"/> <Setter Property="PointerOverFill" Value="Yellow"/> <Setter Property="PointerOverStroke" Value="Transparent"/> </Style> </Input:SfRating.ItemContainerStyle> </Input:SfRating>
C#
SfRating sfrating = new SfRating() { Value = 2, ItemsCount = 5, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, ShowToolTip = false, IsReadOnly = true, Foreground = new SolidColorBrush(Colors.Yellow), Precision=Syncfusion.UI.Xaml.Primitives.Precision.Exact }; Style style = new Style { TargetType = typeof(SfRatingItem) }; Setter setter = new Setter(); setter.Property = SfRatingItem.HeightProperty; setter.Value = 40; Setter setter1 = new Setter(); setter1.Property = SfRatingItem.RatedFillProperty; setter1.Value = new SolidColorBrush(Colors.Yellow); Setter setter2 = new Setter(); setter2.Property = SfRatingItem.WidthProperty; setter2.Value = 40; Setter setter3 = new Setter(); setter3.Property = SfRatingItem.PointerOverFillProperty; setter3.Value = new SolidColorBrush(Colors.Yellow); Setter setter4 = new Setter(); setter4.Property = SfRatingItem.PointerOverStrokeProperty; setter4.Value = new SolidColorBrush(Colors.Transparent); style.Setters.Add(setter); style.Setters.Add(setter1); style.Setters.Add(setter2); style.Setters.Add(setter3); style.Setters.Add(setter4); sfrating.ItemContainerStyle = style; grid.Children.Add(sfrating);
The result based on the above code will the one illustrated on the image below