Xamarin Label will lose alignment when returning a page

I have a label inside the stack layout. This HorizontalTextAlignment parameter is set to TextAlignment.Center . It works correctly when the page is first loaded and when a new value is selected - however, when the page remains and then returns, it loses alignment. This is only a problem on Android, not on iOS. I hope the illustration below helps illustrate my point. This is the only code that affects label alignment, except that it just changes the text through the anchor, but I don’t see how this will change its alignment. Any ideas? Thanks.

 StackLayout durationLayout = new StackLayout { Orientation = StackOrientation.Vertical, WidthRequest = (App.ScreenDpWidth / 3) - (GMStyle.Margin.PageMargin.Left * 2), VerticalOptions = LayoutOptions.Center, Margin = new Thickness(0, 5, 0, 0), HorizontalOptions = LayoutOptions.Start }; durationLabel = new Label { Style = (Style)Application.Current.Resources["DurationLabelStyle"], HorizontalTextAlignment = TextAlignment.Center, //VerticalTextAlignment = TextAlignment.Center, }; durationLabel.SetBinding(Label.TextProperty, "DurationDisplay"); durationLayout.Children.Add(timeSpanPicker); durationLayout.Children.Add(durationLabel); durationLayout.GestureRecognizers.Add(timeSpanTap); 

enter image description here

+7
xamarin xamarin.forms
source share
2 answers

This is a bug in Xamarin Forms, which, I believe, appeared in 2.3.3 or 2.3.4, it works fine in 2.3.2. I don’t know yet, any error report was filed against him, this is the closest that I could find that could be related.

https://bugzilla.xamarin.com/show_bug.cgi?id=49311

As a workaround, you can use HorizontalOptions=LayoutOptions.CenterAndExpand instead of HorizontalTextAlignment .

+18
source share

This is a mistake in the forms of hamarin. You should make your own shortcut renderer, and not update its child plant. Hope it will work.

 public override void ChildDrawableStateChanged(Android.Views.View child) { base.ChildDrawableStateChanged(child); Control.Text = Control.Text; } 
+1
source share

All Articles