如何在 .NET MAUI 7 中将文字包装在标签中?

huangapple go评论118阅读模式
英文:

How can we wrap words in a lable in .net maui 7

问题

这是 .Net Maui <Label> 代码

<Label x:Name="LblName" FontSize="Default" LineBreakMode="WordWrap" TextColor="White"></Label>

我试图使文本换行,但到目前为止,似乎没有任何效果。我已经尝试了所有与"LineBreakMode(s)"一起使用"MaxLines"的方法。

标签中的数据来自代码后台文件,使用"LblName"。我已经尝试了所有与"LineBreakMode(s)"一起使用"MaxLines"的方法。

英文:

Here is the .Net Maui <Label> code

  &lt;Label x:Name=&quot;LblName&quot; FontSize=&quot;Default&quot; LineBreakMode=&quot;WordWrap&quot; TextColor=&quot;White&quot; &gt;&lt;/Label&gt;

I'm trying to wrap the text but so far, nothing seems to be working. I've used all of the "LineBreakMode(s)" in conjunction with the "MaxLines".

The data in label is coming from the code behind file using the "LblName".

I've used all of the "LineBreakMode(s)" in conjunction with the "MaxLines".

答案1

得分: 3

我能够重现这个问题。只能显示一行。

实际上,这是GitHub上已知的问题:在具有列定义的网格中标签无法正确渲染 #10494hartez的评论提供了令人信服的解释,因为列定义设置为自动宽度会导致无限宽度。这个问题目前仍未解决。你可以关注这个帖子。

作为一种解决方法,你可以将列定义设置为*或给定一个具体的值。

希望对你有帮助。

英文:

Well, I can reproduce this issue. Only one line can be shown.

In fact it's a known issue on Github: Label doesn't render correctly when in a Grid with column definitions #10494. And hartez comments gave compelling explanation that it is caused because the ColumnDefinitions is set to Auto which makes a infinite width. This issue is still unsolved now. You could follow this thread.

For workaround, you could set the ColumnDefinitions to * or give a specific value.

Hope it works for you.

huangapple
  • 本文由 发表于 2023年2月18日 18:35:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75492747.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定