static void OnRatingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RatingCell cell = (RatingCell)d;

            for (int i = 0; i < cell.Children.Count; i++)
            {
                cell.Children[i].Opacity = i < cell.Rating ? ON : OFF;
            }
        }
        void img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // calculate rating based on the index of the star
            Image      img   = sender as Image;
            RatingCell cell  = img.Parent as RatingCell;
            int        index = cell.Children.IndexOf(img);

            if (index > 0 || e.GetPosition(img).X > img.Width / 3)
            {
                index++;
            }

            // apply the new rating
            cell.Rating = index;
            Animate(img);
        }