Effectsを使用することで可能です。
各プラットフォームのプロジェクトにEffectsのファイルを作成し、PCL側コントロールのプロパティに作成したEffectsを登録します。
cs
1using Xamarin.Forms;
2
3namespace LineBreakSample
4{
5 public class SamplePage : ContentPage
6 {
7 public SamplePage()
8 {
9 AbsoluteLayout layout = new AbsoluteLayout
10 {
11 HeightRequest = 25
12 };
13
14 Label label = new Label
15 {
16 Text = "テキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキストテキスト",
17 FontSize = 12,
18 VerticalTextAlignment = TextAlignment.Center,
19 };
20 label.Effects.Add(Effect.Resolve("LineBreakSample.LineBreakLabelEffect"));
21
22 AbsoluteLayout.SetLayoutFlags(label, AbsoluteLayoutFlags.All);
23 AbsoluteLayout.SetLayoutBounds(label, new Rectangle(0.5, 0.5, 0.5, 1));
24 layout.Children.Add(label);
25
26 Content = layout;
27 }
28 }
29}
cs
1using Android.Widget;
2using LineBreakSample.Droid.Effects;
3using Xamarin.Forms;
4using Xamarin.Forms.Platform.Android;
5
6[assembly: ResolutionGroupName("LineBreakSample")]
7[assembly: ExportEffect(typeof(LineBreakLabelEffect), "LineBreakLabelEffect")]
8namespace LineBreakSample.Droid.Effects
9{
10 public class LineBreakLabelEffect : PlatformEffect
11 {
12 protected override void OnAttached()
13 {
14 Control.LayoutChange += (s, args) =>
15 {
16 var label = Control as TextView;
17
18 if (label == null) { return; }
19
20 label.Ellipsize = Android.Text.TextUtils.TruncateAt.End;
21 label.SetMaxLines(2);
22 };
23 }
24
25 protected override void OnDetached()
26 {
27 }
28 }
29}
30
cs
1using LineBreakSample.iOS.Effects;
2using UIKit;
3using Xamarin.Forms;
4using Xamarin.Forms.Platform.iOS;
5
6[assembly: ResolutionGroupName("LineBreakSample")]
7[assembly: ExportEffect(typeof(LineBreakLabelEffect), "LineBreakLabelEffect")]
8namespace LineBreakSample.iOS.Effects
9{
10 public class LineBreakLabelEffect : PlatformEffect
11 {
12 protected override void OnAttached()
13 {
14 var label = Control as UILabel;
15
16 if (label == null) { return; }
17 label.LineBreakMode = UILineBreakMode.TailTruncation;
18 label.Lines = 2;
19 }
20
21 protected override void OnDetached()
22 {
23 }
24 }
25}
cs
1using LineBreakSample.UWP.Effects;
2using Xamarin.Forms;
3using Xamarin.Forms.Platform.UWP;
4
5[assembly: ResolutionGroupName("LineBreakSample")]
6[assembly: ExportEffect(typeof(LineBreakLabelEffect), "LineBreakLabelEffect")]
7namespace LineBreakSample.UWP.Effects
8{
9 public class LineBreakLabelEffect : PlatformEffect
10 {
11 protected override void OnAttached()
12 {
13 var label = Control as Windows.UI.Xaml.Controls.TextBlock;
14
15 if (label == null) { return; }
16
17 label.TextWrapping = Windows.UI.Xaml.TextWrapping.Wrap;
18 label.TextTrimming = Windows.UI.Xaml.TextTrimming.WordEllipsis;
19 }
20
21 protected override void OnDetached()
22 {
23 }
24 }
25}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/16 11:27
2016/12/19 00:20