【发布时间】:2020-08-18 16:52:21
【问题描述】:
标题说得最多。我有一个自定义 MarkupExtension,它从字体中获取具有提供名称的图标并将其作为 FontImageSource 返回。该扩展可以在任何可以使用 ImageSource 的地方使用。 扩展本身工作得很好。唯一的问题是,当我使用热重载时,在我的页面上进行一些更改并通过保存更改来重新加载视图,使用我的扩展的所有控件(例如图像)都是空白的。
有什么方法可以让我的 MarkupExtension 与 Hot Reload 一起使用?
示例代码:
[ContentProperty(nameof(IconName))]
public class FontImageExtension : IMarkupExtension<ImageSource>
{
private readonly IconFontService iconFontService;
public string IconName { get; set; }
public FontImageExtension()
{
iconFontService = GetService();
}
public ImageSource ProvideValue(IServiceProvider serviceProvider)
{
if (string.IsNullOrEmpty(IconName))
return null;
string glyphCode = iconFontService.GetGlyphCode(IconName);
if (string.IsNullOrEmpty(glyphCode))
return null;
return new FontImageSource()
{
FontFamily = iconFontService.GetFontLocation(),
Glyph = glyphCode,
};
}
object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
{
// Converting back is not needed
return null;
}
}
【问题讨论】:
-
我认为cs文件中的代码不能使用热重载
-
Hot reload 有一大堆限制,并且在最好的日子里受到相当的打击和错过。这是一个很大的改进,但仍在进行中 IMO
标签: c# xaml xamarin xamarin.forms markup-extensions