Xamarin标签在页面返回到时失去文本对齐方式 [英] Xamarin Label losing text alignment when page returned to

查看:105
本文介绍了Xamarin标签在页面返回到时失去文本对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在堆栈布局中有一个标签.它的HorizontalTextAlignment设置为TextAlignment.Center.它在页面的初次加载时可以正常工作,并且在选择新值时有效-但是,当离开页面然后返回页面时,它将失去对齐状态.这只是Android上的问题,而不是iOS上的问题.我希望下面的图片可以帮助说明我的观点.这是唯一会影响Label对齐方式的代码,除了它只是通过绑定更改其文本外,但我看不到它将如何更改其对齐方式.有任何想法吗?谢谢.

I have a label inside of a stack layout. It has its HorizontalTextAlignment set to TextAlignment.Center. It works correctly on the initial loading of the page, and when a new value is selected - however when the page is left and then returned to, it loses its alignment. This is only a problem on Android and not on iOS. I hope the image below can help illustrate my point. This is the only code that affects the Label's alignment, other than that it's just changing it's text through a binding, but I don't see how that would change it's 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);

推荐答案

这是Xamarin Forms中的错误,我相信它出现在2.3.3或2.3.4中,在2.3.2中可以正常工作.我还不知道有任何关于它的错误报告,这是我所发现的最接近的,可能是相关的.

This is a bug in Xamarin Forms, that I believe appeared in 2.3.3 or 2.3.4, it works fine in 2.3.2. I don't know of any bug report lodged against it just yet, this is the closest I could find, that may be related.

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

作为解决方法,可以使用HorizontalOptions=LayoutOptions.CenterAndExpand代替HorizontalTextAlignment.

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

这篇关于Xamarin标签在页面返回到时失去文本对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆