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

Custom Renderer - Modify specific XAML properties

$
0
0

Hi,

I'm using Xamarin 4 with Xamarin.Forms 2.0. I created a custom renderer on Android to display a custom font. Now I would like to link the XAML FontAttributes property value (e.g. Bold) to a specific font type, e.g. (Open Sans Bold.ttf). How can I do this?

PCL XAML:

        <controls:ExtendedLabel
          Text="Welcome"
          FontFamily="2Dumb"
          HorizontalOptions="CenterAndExpand"/>

Android
namespace MolinaMemberApp.CustomControls
{
public class ExtendedLabel : Label {}
}

[assembly: ExportRenderer(typeof(ExtendedLabel), typeof(ExtendedLabelRenderer))]
namespace MolinaMemberApp.Droid.CustomControls
{
public class ExtendedLabelRenderer : LabelRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Label> e)
{
base.OnElementChanged(e);
var label = (TextView)Control; // for example
Typeface font = Typeface.CreateFromAsset(Forms.Context.Assets, "2Dumb_webfont.ttf");
label.Typeface = font;
}
}
}


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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