Plugin.SegmentedControl icon indicating copy to clipboard operation
Plugin.SegmentedControl copied to clipboard

Center Alignment gets lost when selecting a segment

Open bluekuen opened this issue 5 years ago • 12 comments

I set the width to fit the App.ScreenWidth. When selecting a segment the text gets aligned to the start : first: image then: image

This is the control xaml code:

 <control:SegmentedControl 
                            x:Name="SegmentedControl" 
                             WidthRequest="{Binding SegmentedControlWidth, Mode=TwoWay}"
                            HorizontalOptions="StartAndExpand"
                            VerticalOptions="StartAndExpand"  
                            SelectedSegment="{Binding SelectedSegment, Mode=TwoWay}" 
                            TintColor="{StaticResource ZAblue}"
                            SelectedTextColor="White"
                            DisabledColor="Gray"
                            FontSize="12"
                            HeightRequest="35">
                            <control:SegmentedControl.Behaviors>
                                <behaviors:EventToCommandBehavior
                                    EventName="OnSegmentSelected"
                                    Command="{Binding OnSegmentSelectedCommand}"
                                    CommandParameter="{Binding .}"/>
                            </control:SegmentedControl.Behaviors>
</control:SegmentedControl>

And this is in my ViewModel:

[Reactive]
public ObservableCollection<SegmentedControlOption> SegmentedControlChildren { get; set; } = new ObservableCollection<SegmentedControlOption>();
public void SetupSegmentedControl()
        {
            var guidConverter = new GuidToStringConverter();
            calculateVisibleSegments(_menuMainItem.Menus.Count);
            var segmentControlItems = new ObservableCollection<SegmentedControlOption>();
            foreach (DeviceMenuItem menu in _menuMainItem.Menus)
            {
                string menuNametext = (string)guidConverter.Convert(menu.Name, typeof(Guid), null, null);
                
                if (!ParameterAndSubMenusEmpty(menu, _deviceService.GetDevice().AccessLevel))
                {
                    SegmentedControlOption segControl = new SegmentedControlOption();
                    segControl.Text = menuNametext;
                    //segControl.Id = menu.ID;
                    if (segmentControlItems.FirstOrDefault(seg => seg.Text == menuNametext) == null)
                    {
                        segmentControlItems.Add(segControl);
                    }
                }                
            }

            SegmentedControlChildren = segmentControlItems;
            calculateVisibleSegments(SegmentedControlChildren.Count);            
            //SelectedSegment = selectedSegment;
        }
        public void calculateVisibleSegments(int segments)
        {
            int min = 360;
            int visibleSegments = 3;

            while (App.ScreenWidth > min)
            {
                min += 150;
                visibleSegments++;
            }

            if (segments <= visibleSegments)
            {
                SegmentedControlWidth = App.ScreenWidth - 10;
            }
            else
            {
                SegmentedControlWidth = (App.ScreenWidth / visibleSegments) * segments + 150;
            }

        }

I already tried:

  • removing scrollview
  • move it out of stacklayout
  • remove the TwoWay Bindings
  • change the selectedCommand from Behavior to property

bluekuen avatar Sep 11 '19 09:09 bluekuen

What device(s) do you see behavior on? iOS, Android, UWP, Mac?

Also please check if this issue have been solved with v4.2.0.

1iveowl avatar Oct 16 '19 10:10 1iveowl

It's just on Android, tested with Samsung Galaxy S7.

bluekuen avatar Oct 16 '19 12:10 bluekuen

Is the issue still there after I updated the package to 4.2.0 earlier today?

1iveowl avatar Oct 16 '19 12:10 1iveowl

I will test it

bluekuen avatar Oct 16 '19 12:10 bluekuen

I have the same issue when loading on TabbedPage. Screen Shot 2019-10-18 at 2 32 28 PM

Firice avatar Oct 18 '19 07:10 Firice

yeah sorry for delay, problem still exists with 4.2.0.

bluekuen avatar Oct 18 '19 10:10 bluekuen

Thank you @bluekuen.

For the moment, I don't know what causes this nor how to fix it, but I will look closer at it to see if I can fix it.

My understanding is that this is an Android issue, only.

1iveowl avatar Oct 18 '19 12:10 1iveowl

No problem, yes it's only on Android. Thank you for this great Plugin!

bluekuen avatar Oct 18 '19 12:10 bluekuen

Hello, I have the same issue. But only when returning from another page (activity). So I have the segmented buttons below a listview. When I click on an item in the listview the application opens a detail page. Click on back to return to the page with the segmented buttons. Now click on a segmented button and the text aligns left and it's width changes to half of what is was before.

e-vw avatar Oct 28 '19 15:10 e-vw

I am experiencing the same behavior as @e-vw. Any updates or suggestions of a possible work around for Android?

trnacctKR avatar Apr 17 '20 17:04 trnacctKR

@bluekuen @e-vw @skraymo Did anyone find a work around for this?

robfrancis avatar Nov 12 '20 00:11 robfrancis

I am also experiencing this issue when hiding/showing a layout that contains a segmented control and also only on Android. Currently on version 5.4.5.

For me, the issue resolves itself and the text alignment is correct once I tap on the segment.

mjrichards91 avatar Mar 23 '21 14:03 mjrichards91