Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to set a Label's maximum lines when FastRenderers is enabled ?

$
0
0

Hi all,
I used to add an Effect to a Label whenever I wanted to set the maximum lines of text to show.
Now if I enable the FastRenderers, the code below does not work anymore.
It DOES work just fine when the FastRenderers flag is not set.

Any clues, please?

using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Android.Text;
using PCLEffect = Sample.MultiLineEffect;
using Android.Widget;

[assembly: ExportEffect(typeof(Sample.Droid.Effects.MultiLineEffect), "MultiLine")]
namespace Sample.Droid.Effects
{
    public class MultiLineEffect : PlatformEffect
    {
        protected override void OnAttached() {
            var effect = (PCLEffect)Element.Effects.FirstOrDefault(e => e is PCLEffect);
            if (Control is TextView tv) {
                var maxLines = effect.MaxLines;
                if (maxLines > 0) {
                    tv.Ellipsize = TextUtils.TruncateAt.End;
                    tv.SetSingleLine(false);
                    tv.SetMaxLines(maxLines);
                }
            }
        }

        protected override void OnDetached() {
        }
    }
}

Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>