Xamarin形成Label新行

Ido*_*doT 7 android xamarin xamarin.forms

我有一个Label在我的Xamarin表单页面,它Text从它的视图模型接收它,并且文本包含该\n字符.如何Label自动将文本拆分为两个不同的行?

Ran*_*mar 21

非常简单,添加以下unicode而不是\n

 

Run Code Online (Sandbox Code Playgroud)

对于前:

Text="General 
 Studies - I"
Run Code Online (Sandbox Code Playgroud)


Mot*_*mbo 12

解决这个问题的一种方法是将虚拟机中的 '\n' 替换为System.Environment.NewLine

string Text = "Text first line\nText second line".Replace("\n", System.Environment.NewLine);

/sf/answers/3988680181/


小智 6

你可以这样做:

Text = "First line string
Second line string"
Run Code Online (Sandbox Code Playgroud)


Ale*_*Lau 2

从Xamarin 论坛中的线程复制

可能是你的代码:

<Label FontSize="Medium" TextColor="Gray" Text="{translation:TranslationResource MyExpertsView_NoExpertsText}"  IsVisible="{Binding IsNoExpertsFound}"></Label>
Run Code Online (Sandbox Code Playgroud)

由于您的文本是从资源文件中检索的,因此Text属性将Label输入视为纯文本并且不允许任何转义字符。

您可以考虑预处理 .txt 文件中的字符串(将所有 \n 替换为换行符)TranslationResource