Пример #1
0
        private void GenrateBarStepper()
        {
            StackLayout Outerstack = new StackLayout
            {
            };
            StackLayout stack = new StackLayout
            {
                Margin      = new Thickness(15, 0),
                Spacing     = 0,
                Orientation = StackOrientation.Horizontal
            };

            for (int i = 0; i < Steps; i++)
            {
                var frame = new Frame
                {
                    HorizontalOptions = LayoutOptions.Center,
                    CornerRadius      = 50,
                    HasShadow         = false
                };
                if (ImageSourceCollection != null && ImageSourceCollection?.Count != 0)
                {
                    var img = new Image
                    {
                        Source = i < CurrentStep?SelectedImageSourceCollection[i]:ImageSourceCollection[i],
                    };
                    img.SetBinding(Image.StyleProperty, new Binding(ImageStyleProperty.PropertyName, source: this));
                    frame.Padding         = new Thickness(0);
                    frame.BackgroundColor = Color.Transparent;
                    frame.Content         = img;
                }
                else
                {
                    frame.SetBinding(Frame.PaddingProperty, new Binding(CircleWidthProperty.PropertyName, source: this));
                    if (i < CurrentStep)
                    {
                        frame.SetBinding(Frame.BackgroundColorProperty, new Binding(SelectedStapsColorProperty.PropertyName, source: this));
                    }
                    else
                    {
                        frame.SetBinding(Frame.BackgroundColorProperty, new Binding(StepsColorProperty.PropertyName, source: this));
                    }
                }
                if (i == 0)
                {
                    stack.Children.Add(frame);
                    continue;
                }
                var boxview = new BoxView
                {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.Center,
                };
                boxview.SetBinding(BoxView.HeightRequestProperty, new Binding(StripWidthProperty.PropertyName, source: this));
                if (i < CurrentStep)
                {
                    boxview.SetBinding(BoxView.ColorProperty, new Binding(SelectedStapsColorProperty.PropertyName, source: this));
                }
                else
                {
                    boxview.SetBinding(BoxView.ColorProperty, new Binding(StripColorProperty.PropertyName, source: this));
                }
                stack.Children.Add(boxview);
                stack.Children.Add(frame);
                stack.Children.ToList().ForEach((frm) =>
                {
                    frm.GestureRecognizers?.Clear();
                    if (frm.GetType() == typeof(Frame))
                    {
                        TapGestureRecognizer tapGesture = new TapGestureRecognizer();
                        tapGesture.Tapped += (s, e) =>
                        {
                            var index = stack.Children.Where(view => view.GetType() == typeof(Frame)).ToList()?.IndexOf(frm);
                            TabEventHandler?.Invoke(this, new TabEventArgs {
                                TabIndex = index
                            });
                            TabCommand?.Execute(TabCommandParameter);
                        };
                        frm.GestureRecognizers.Add(tapGesture);
                    }
                });
            }
            Outerstack.Children.Add(stack);
            if (TagsSource != null || TagsSource?.Count >= Steps)
            {
                StackLayout tagstack = new StackLayout
                {
                    Orientation = StackOrientation.Horizontal
                };
                for (int i = 0; i < Steps; i++)
                {
                    var label = new Label
                    {
                        Text = TagsSource[i],
                        HorizontalOptions = LayoutOptions.CenterAndExpand
                    };
                    if (i == 0)
                    {
                        label.HorizontalOptions = LayoutOptions.StartAndExpand;
                    }
                    if (i == Steps - 1)
                    {
                        label.HorizontalOptions = LayoutOptions.EndAndExpand;
                    }
                    label.SetBinding(Label.StyleProperty, new Binding(LabelStyleProperty.PropertyName, source: null));
                    tagstack.Children.Add(label);
                }
                Outerstack.Children.Add(tagstack);
            }
            Content = Outerstack;
        }