gpt4 book ai didi

c# - 当标签的文本更改时,标签的字体变回默认值

转载 作者:太空宇宙 更新时间:2023-11-03 15:40:02 25 4
gpt4 key购买 nike

我使用自定义渲染器来设置字体。问题是当我更改标签的文本时,字体样式消失了。

提供了我的自定义渲染器代码。谁能告诉我我做错了什么??

[assembly: ExportRenderer (typeof (MyLabel), typeof (MyLabelRenderer))]
namespace FormsProj.Droid
{
public class MyLabelRenderer : LabelRenderer
{
protected override void OnElementChanged (ElementChangedEventArgs<Label> e)
{
base.OnElementChanged (e);

var label = (TextView)Control;
Typeface font = Typeface.CreateFromAsset (Forms.Context.Assets, "Raleway-Regular.ttf");
label.Typeface = font;
}
}
}

更新#1这是我的代码共享项目 使用系统; 使用 Xamarin.Forms;

namespace FormsProj
{
public class MyLabel:Label
{
}
}

在我使用 MyLabel 的地方编写代码

var Thankyoutxt = new MyLabel {
XAlign = TextAlignment.Center,
Text = "Thank You",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.Center,
TextColor = Xamarin.Forms.Color.White,
FontAttributes = FontAttributes.Bold,
Style = Device.Styles.CaptionStyle,
FontFamily = ColorandFont.FontName,

};

单击按钮我将更改文本,届时字体会变回没有自定义字体..

提前致谢..:)

最佳答案

您可能还想尝试在渲染器中重置 OnPropertyChangedEvent 的属性。过去我遇到过这个问题,现在已经解决了。

关于c# - 当标签的文本更改时,标签的字体变回默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30578070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com