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

Spannable string with custom renderer

$
0
0

Hello.

I have problem and I can't understand what is wrong.
1. I have MyButton : Xamarin.Forms.Button
2. I have custom renderer:

    protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
    {
        base.OnElementChanged(e);
        Control.TextFormatted = SpannableString(Text);  
    }

    private ISpannable SpannableString(string text)
    {
        SpannableString spannableString = new SpannableString(text);
        spannableString.SetSpan(new ForegroundColorSpan(Android.Graphics.Color.Red), 1, 3, SpanTypes.ExclusiveExclusive);
        spannableString.SetSpan(new BackgroundColorSpan(Android.Graphics.Color.Red), 0, 3, SpanTypes.ExclusiveExclusive);
        spannableString.SetSpan(new UnderlineSpan(), 0, 3, SpanTypes.ExclusiveExclusive);
        return spannableString;
    }

And what I have:
Xamarin uses Text field from MyButton and ignore renderer, but on click event Xamarin use TextFormatted, but text is not formatted.

Does Xamarin support TextFormatted for Button?
And How Can I use this in custom renderer?

Thanks.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



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