が、2つのラインを、どのような作品です、 それは動作しません。テキストは3行目になります。
カスタムラベルコントロールを作成し、XAMLでそれを消費することができます。
CustomLabel:
public class CustomLabel:Label
{
}
XAML:
<ContentPage ...
xmlns:local="clr-namespace:LabelDemo"
...>
<local:CustomLabel Text="I'm a baby not robot. \nPlease give me a milk" VerticalOptions="Center" HorizontalOptions="Center" />
その後、カスタムを作成あなたのDroidプロジェクトのレンダラーは以下のようになります:
using Android.Widget;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
[assembly:ExportRenderer(typeof(LabelDemo.CustomLabel),typeof(LabelDemo.Droid.MyLabelRenderer))]
namespace LabelDemo.Droid
{
public class MyLabelRenderer:LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var text = Control.Text;
text = text.Replace("\\n", "\n");//"\n" in shared project will be automatically transformed into "\\n", so we need to change it back
Control.SetLines(2);
Control.SetText(text, TextView.BufferType.Normal);
}
}
}
}
[この](http://stackoverflow.com/questions/5460256/string-resource-new-line-n-not-possibleが)それは私がそれについて申し訳ありません –
を助けることを願う表示しよう。私はEditTextではなく、2行のTextViewを作ろうとしています。私は質問を編集しました。 –
XamarinフォームにTextViewがありません。明確にすることはできますか? –