void RebuildButtons()
        {
            this.ColumnDefinitions.Clear();
            this.Children.Clear();

            for (int i = 0; i < SegmentedButtons.Count; i++)
            {
                var buttonSeg = SegmentedButtons[i];

                var label = new Label
                {
                    Text  = buttonSeg.Title,
                    Style = LabelStyle,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Center
                };

                this.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
                var frame = new AdvancedFrame();
                if (i == 0)
                {
                    frame.Corners = RoundedCorners.Left;
                }
                else if ((i + 1) == SegmentedButtons.Count)
                {
                    frame.Corners = RoundedCorners.Right;
                }
                else
                {
                    frame.Corners = RoundedCorners.None;
                }

                frame.CornerRadius      = CornerRadius;
                frame.OutlineColor      = OnColor;
                frame.Content           = label;
                frame.HorizontalOptions = LayoutOptions.FillAndExpand;
                frame.VerticalOptions   = LayoutOptions.FillAndExpand;

                if (i == SelectedIndex)
                {
                    frame.InnerBackground = OnColor;
                    label.TextColor       = OffColor;
                }
                else
                {
                    frame.InnerBackground = OffColor;
                    label.TextColor       = OnColor;
                }

                var tapGesture = new TapGestureRecognizer();
                tapGesture.Command          = ItemTapped;
                tapGesture.CommandParameter = i;
                frame.GestureRecognizers.Add(tapGesture);

                this.Children.Add(frame, i, 0);
            }
        }
Пример #2
0
        void RebuildButtons()
        {
            this.ColumnDefinitions.Clear();
            this.Children.Clear();

            for (int i = 0; i < SegmentedButtons.Count; i++)
            {
                var buttonSeg = SegmentedButtons[i];

                double fontSize;    // local variable to save the interpreted font size
                try
                {
                    // convert the normal names first
                    fontSize = Device.GetNamedSize((NamedSize)Enum.Parse(typeof(NamedSize), FontSize, true), typeof(Label));
                }
                catch (Exception)
                {
                    // convert as a double and default if there is a problem
                    if (double.TryParse(FontSize, out fontSize) == false)
                    {
                        fontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label));
                    }
                }

                var label = new Label
                {
                    Text     = buttonSeg.Title,
                    FontSize = fontSize,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Center
                };

                this.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
                var frame = new AdvancedFrame();
                if (i == 0)
                {
                    frame.Corners = RoundedCorners.left;
                }
                else if ((i + 1) == SegmentedButtons.Count)
                {
                    frame.Corners = RoundedCorners.right;
                }
                else
                {
                    frame.Corners = RoundedCorners.none;
                }

                frame.CornerRadius      = CornerRadius;
                frame.OutlineColor      = OnColor;
                frame.Content           = label;
                frame.HorizontalOptions = LayoutOptions.FillAndExpand;
                frame.VerticalOptions   = LayoutOptions.FillAndExpand;

                if (i == SelectedIndex)
                {
                    frame.InnerBackground = OnColor;
                    label.TextColor       = OffColor;
                }
                else
                {
                    frame.InnerBackground = OffColor;
                    label.TextColor       = OnColor;
                }

                var tapGesture = new TapGestureRecognizer();
                tapGesture.Command          = ItemTapped;
                tapGesture.CommandParameter = i;
                frame.GestureRecognizers.Add(tapGesture);

                this.Children.Add(frame, i, 0);
            }
        }