예제 #1
0
        private void Button_Clicked(object sender, EventArgs e)
        {
            string str = ((StarPicker)((StackLayout)(((Button)sender).Parent)).Children[0]).SelectedItem.ToString();

            NamesOfStars.Remove(str);
            NamesOfStars.Add(str, -1);
            int index = StarsStack.Children.IndexOf((View)((Button)sender).Parent);

            for (int i = 0, count = NamesOfStars.Count; i < count; i++)
            {
                int value = NamesOfStars.ElementAt(i).Value;
                if (value > index)
                {
                    string key = NamesOfStars.ElementAt(i).Key;
                    value--;
                    NamesOfStars.Remove(key);
                    NamesOfStars.Add(key, value);
                }
            }
            StarsStack.Children.Remove((View)((Button)sender).Parent);
            for (int i = 0, count = StarsStack.Children.Count; i < count; i++)
            {
                StarPicker picker1 = (StarPicker)((StackLayout)StarsStack.Children[i]).Children[0];
                picker1.SelectedIndexChanged -= StarPicker_SelectedIndexChanged;
                string tempSelectedItem = (string)picker1.SelectedItem;
                picker1.RefreshItems(NamesOfStars, i);
                picker1.SelectedItem          = tempSelectedItem;
                picker1.SelectedIndexChanged += StarPicker_SelectedIndexChanged;
            }
        }
예제 #2
0
        private void StarPicker_SelectedIndexChanged(object sender, EventArgs e)
        {
            int    index;
            string selectedItem = (string)((StarPicker)sender).SelectedItem;

            if (sender == ((StackLayout)StarsStack.Children[StarsStack.Children.Count - 1]).Children[0])
            {
                index = StarsStack.Children.Count - 1;
                NamesOfStars[selectedItem] = StarsStack.Children.Count - 1;
                Button button = new Button()
                {
                    Text        = "-", TextColor = Color.Black, CornerRadius = 30, FontSize = 20, BackgroundColor = Color.FromHex("#60757575"),
                    BorderColor = Color.Black, WidthRequest = 40
                };
                button.Clicked += Button_Clicked;
                ((StackLayout)StarsStack.Children[StarsStack.Children.Count - 1]).Children.Add(button);
                StarPicker picker = new StarPicker(NamesOfStars);
                picker.SelectedIndexChanged += StarPicker_SelectedIndexChanged;
                StackLayout stack = new StackLayout()
                {
                    Orientation = StackOrientation.Horizontal
                };
                stack.Children.Add(picker);
                StarsStack.Children.Add(stack);
            }
            else
            {
                index = StarsStack.Children.IndexOf((View)((StarPicker)sender).Parent);
                string str = NamesOfStars.ElementAt(NamesOfStars.Values.ToList().IndexOf(index)).Key;
                NamesOfStars.Remove(str);
                NamesOfStars.Add(str, -1);
                NamesOfStars[selectedItem] = index;
            }
            for (int i = 0, count = StarsStack.Children.Count; i < count; i++)
            {
                if (i != index)
                {
                    StarPicker picker1 = ((StarPicker)((StackLayout)StarsStack.Children[i]).Children[0]);
                    picker1.SelectedIndexChanged -= StarPicker_SelectedIndexChanged;
                    string tempSelectedItem = (string)picker1.SelectedItem;
                    picker1.RefreshItems(NamesOfStars, i);
                    picker1.SelectedItem          = tempSelectedItem;
                    picker1.SelectedIndexChanged += StarPicker_SelectedIndexChanged;
                }
            }
        }