Exemplo n.º 1
0
        /// <summary>
        /// Set the visual state for the stars
        /// </summary>
        /// <param name="check">User selected star</param>
        /// <param name="rat">reference to the instance of this control</param>
        private static void SetStars(CheckBox check, RateControl rat)
        {
            if (rat != null)
            {
                checkingInProgress = true;

                bool found = false;
                
                // we want to empty the selection, so cheat the check routine
                if (check == null)
                {
                    found = true;
                }

                // Loop through the stars and light them on if they are 
                // below selected and dim if they are above the selected
                for (int i = 0; i < rat.stars.Count; i++)
                {
                    if (check != rat.stars[i])
                    {
                        if (!found)
                        {
                            rat.stars[i].IsChecked = true;
                        }
                        else
                        {
                            rat.stars[i].IsChecked = false;
                        }
                    }
                    else
                    {
                        found = true;
                        rat.stars[i].IsChecked = true;
                        rat.Rating = i + 1;
                    }
                }
                checkingInProgress = false;
            }
        }
Exemplo n.º 2
0
        private static void CreateStars(RateControl rat, int? amount)
        {
            if (amount == null)
            {
                amount = 1;
            }
            
            // Do the cleanup for the old stuff
            foreach (CheckBox box in rat.stars)
            {
                rat.LayoutRoot.Children.Remove(box);
            }
            rat.stars.Clear();
            List<ColumnDefinition> columnDefinitionsToRemove = new List<ColumnDefinition>();
            foreach (ColumnDefinition def in rat.LayoutRoot.ColumnDefinitions)
            {
                columnDefinitionsToRemove.Add(def);
            }

            foreach (ColumnDefinition def in columnDefinitionsToRemove)
            {
                rat.LayoutRoot.ColumnDefinitions.Remove(def);
            }
            
            rat.Rating = 0;
            
            // Create the new controls
            for (int i = 0; i < amount; ++i)
            {
                rat.LayoutRoot.ColumnDefinitions.Add(new ColumnDefinition());
                CheckBox check = new CheckBox();
                check.Name = "check" + i.ToString();
                check.SetValue(Grid.ColumnProperty, i);

                check.HorizontalAlignment = HorizontalAlignment.Left;
                check.Checked += new RoutedEventHandler(OnCheck);
                check.Unchecked += new RoutedEventHandler(OnCheck);
                rat.stars.Add(check);
                rat.LayoutRoot.Children.Add(check);
            }
        }