Issue
I made a Xamarin.Forms project and I referenced my own font and then added an alias in the assembly like so:
[assembly: ExportFont("Samantha.ttf", Alias = "MyAwesomeCustomFont")]
Now... the thing is, this font which I have referenced is NOT being shown in the designer, instead I'm still getting the default font, even after referencing it:
<Button WidthRequest="70" Text="Click me" FontFamily="MyAwesomeCustomFont"/>
Now, this is frustrating because it is working when I deploy it and it showing the font although I want the designer to illustrate exactly what's going on, so I do want the custom font to be shown in the designer... Is this possible?
Thanks,
Solution
I've solved my own problem. I created a custom renderer and it's showing in the preview:
[assembly: ExportRenderer(typeof(Xamarin.Forms.Button), typeof(CustomButtonRenderer))]
namespace Custombutton.Droid
{
class CustomButtonRenderer : ButtonRenderer
{
public CustomButtonRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.SetAllCaps(false);
Typeface tf = Typeface.CreateFromAsset(Android.App.Application.Context.Assets, "NUNITO-BOLD.ttf");
Control.SetTypeface(tf, TypefaceStyle.Bold);
}
}
}
}
Result in designer:
Answered By - user14090664
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.