private static void InnerRatingValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { RatingBar parent = sender as RatingBar; Int32 ratingValue = (Int32)e.NewValue; UIElementCollection children = (parent.Content as StackPanel).Children; ToggleButton button = null; if (!children.Any()) { return; } for (Int32 i = 0; i < ratingValue; i++) { button = children[i] as ToggleButton; button.IsChecked = true; } for (Int32 i = ratingValue; i < children.Count; i++) { button = children[i] as ToggleButton; button.IsChecked = false; } }
private static void ValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { UIElementCollection children = ((sender as Rating)?.Content as Panel)?.Children; if (children == null || !children.Any()) { return; } int ratingValue = (int)e.NewValue; for (int i = 0; i < children.Count; i++) { (children[i] as TextBlock).Text = i <= ratingValue ? "\uE0B4" : "\uE224"; } }