Xamarin 标签/选择器中的换行符不正确
有时,我在标签中的文本或Android中的选取器会在标签结束前换行。这并不是每次都会发生,但当它发生时,文本最初会正确显示,然后快速错误地重新渲染。只有当视图在网格中时才会发生这种情况,但我不能确定这是原因。使用“ShowLayoutBounders”选项,我可以看到标签的宽度是正确的,并且没有改变,只是换行不正确 ContentView子类构造函数中的相关代码:Xamarin 标签/选择器中的换行符不正确,xamarin,xamarin.forms,Xamarin,Xamarin.forms,有时,我在标签中的文本或Android中的选取器会在标签结束前换行。这并不是每次都会发生,但当它发生时,文本最初会正确显示,然后快速错误地重新渲染。只有当视图在网格中时才会发生这种情况,但我不能确定这是原因。使用“ShowLayoutBounders”选项,我可以看到标签的宽度是正确的,并且没有改变,只是换行不正确 ContentView子类构造函数中的相关代码: Grid _contentGrid = new Grid() { RowDefinitions = new RowDefin
Grid _contentGrid = new Grid()
{
RowDefinitions = new RowDefinitionCollection()
{
new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
},
ColumnDefinitions = new ColumnDefinitionCollection()
{
new ColumnDefinition() { Width = 48 },
new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) },
},
BackgroundColor = Color.Transparent,
Padding = new Thickness(16, 16, 16, 16),
ColumnSpacing = 16,
RowSpacing = 8,
HorizontalOptions = LayoutOptions.FillAndExpand
};
Label _questionLabel = new Label()
{
Text = "Do you want to update the instrument setup?",
TextColor = Color.FromHex(Colours.TextGrey),
HorizontalOptions = LayoutOptions.FillAndExpand,
XAlign = TextAlignment.Start,
WidthRequest = 344
};
_contentGrid.Children.Add(_questionLabel, 0, 2, 3, 4);
DialogView dialogView = new DialogView()
{
TopView = TitleLabel,
MiddleView = _contentGrid,
BottomView = ButtonGrid,
TopColour = Color.FromHex(Colours.Blue),
MiddleColour = Color.White,
BottomColour = Color.White,
MiddleHeight = 150,
};
Grid Holder = new Grid()
{
ColumnDefinitions = new ColumnDefinitionCollection()
{
new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) },
new ColumnDefinition() { Width = 368 },
new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) },
},
RowDefinitions = new RowDefinitionCollection()
{
new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) },
new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) },
},
BackgroundColor = Color.FromHex("b0000000")
};
Holder.Children.Add(dialogView, 1, 1);
this.Content = Holder;
“问题标签”文本仅显示“是否需要”是否指定了
LineBreakMode=LineBreakMode.NoWrap代码>@Mario Galván我有,但没有用。这就好像文字的宽度放错了。另外,这对没有LineBreakMode属性的选取器没有帮助。嗯,可能它与tour GridLenth或LayoutOptions有关。FillAndExpand,为所有布局和视图(标签和选取器)上色可能会有帮助,以查看哪一个会影响标签/选取器视图。这就是问题所在,没有其他观点会影响它。我通过切换到stacklayout来修复它,因为在本例中只有一列。这似乎是Grid的自动gridlength的问题。如果屏幕更新影响到标签所在的网格,我可能会遇到标签丢失文本对齐的相关错误。在每种情况下,父链中的某个地方都有一个网格在自动调整大小