【发布时间】:2018-06-02 07:24:47
【问题描述】:
使用 Xamarin Forms(版本 2.5.0.121934),我正在开发一个面向 Android、iOS 和 UWP 的应用程序。我需要为一些需要自定义渲染器的文本添加下划线和删除线。对于 Android 和 iOS,一切正常,在 UWP 上,应用删除线或下划线正常工作,但删除这些装饰不起作用。
这是整个 UWP 渲染器:
[assembly: ExportRenderer(typeof(EnhancedLabel), typeof(EnhancedLabelRenderer))]
namespace myApp.UWP
{
public class EnhancedLabelRenderer : LabelRenderer
{
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
var strikethrough = ((EnhancedLabel)sender).Strikethrough;
var underline = ((EnhancedLabel)sender).Underline;
if (strikethrough && underline)
{
Control.TextDecorations = TextDecorations.Strikethrough | TextDecorations.Underline;
}
else if (strikethrough)
{
Control.TextDecorations = TextDecorations.Strikethrough;
}
else if (underline)
{
Control.TextDecorations = TextDecorations.Underline;
}
else
{
Control.TextDecorations = TextDecorations.None;
}
}
}
}
EnhancedLabel 是一个简单的类,它扩展了Xamarin.Forms.Label 并添加了指定删除线或下划线的简单BindableProperty 字段。
渲染器正确设置了TextDecorations.None,但这对 UI 没有影响。我已经在调试器中解决了这个问题,实际上可以看到ExtendedLabel 中TextBlock 的状态有TextDecorations.None,但UI 仍然用下划线或删除线绘制它(基本上,其中任何一个都可以可以添加,但都不能删除)。
我浏览了 Xamarin 文档并查看了 Bugzilla 中的错误,但没有找到任何线索。有人遇到过这种情况么?想知道是否有我错过的特定于 UWP 的调用,或者使用 TextDecorations 是否是应用样式的错误方法,或者我是否真的偶然发现了一个错误。
【问题讨论】:
-
朋友指点我stackoverflow.com/questions/16480344/…;适用于 WPF 的方法不适用于 UWP。
标签: xamarin xamarin.forms uwp