[英]Previewing Fonts in Designer in Xamarin.FORMS
我做了一个 Xamarin.Forms 项目,我引用了我自己的字体,然后在程序集中添加了一个别名,如下所示:
[assembly: ExportFont("Samantha.ttf", Alias = "MyAwesomeCustomFont")]
现在......问题是,我引用的这个字体没有显示在设计器中,相反,即使在引用它之后,我仍然获得默认字体:
<Button WidthRequest="70" Text="Click me" FontFamily="MyAwesomeCustomFont"/>
现在,这令人沮丧,因为当我部署它时它正在工作并且它显示字体虽然我希望设计器准确说明发生了什么,所以我确实希望在设计器中显示自定义字体......这可能吗?
谢谢,
我已经解决了我自己的问题。 我创建了一个自定义渲染器,它显示在预览中:
[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);
}
}
}
}
结果在设计师:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.