首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法清除Xamarin Forms UWP应用程序中的TextDecoration

无法清除Xamarin Forms UWP应用程序中的TextDecoration
EN

Stack Overflow用户
提问于 2017-12-20 03:39:21
回答 1查看 629关注 0票数 0

使用Xamarin Forms (版本2.5.0.121934),我正在开发一个针对Android、iOS和UWP的应用程序。我需要添加下划线和删除线到一些文本,这需要自定义渲染器。对于Android和iOS,一切都运行得很好,在UWP上,应用删除线或下划线可以正常工作,但删除这些装饰就不起作用了。

下面是UWP渲染器的全部内容:

代码语言:javascript
复制
[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产生影响。我已经在调试器中完成了这项工作,实际上可以看到ExtendedLabelTextBlock的状态为TextDecorations.None,但UI仍然使用下划线或删除线来绘制它(本质上,这两种方式都可以添加,但都不能删除)。

我已经浏览了Xamarin文档并查看了Bugzilla中的bug,但没有找到任何线索。还有没有其他人遇到过这种情况?我想知道是否有一个特定于UWP的调用我错过了,或者使用TextDecorations是不正确的应用样式的方式,或者我是否真的偶然发现了一个错误。

EN

回答 1

Stack Overflow用户

发布于 2019-06-11 00:19:46

UWP中的错误,如下面的Xaml中的:

代码语言:javascript
复制
                <TextBlock>
                    <Run  Text="Decorations can be toggled on and off"/>
                </TextBlock>

                <TextBlock Text="Decorations will not toggle off"/>

如果对TextBlock进行编码,也会出现同样的问题:

代码语言:javascript
复制
        TextBlock textBlock = new TextBlock { FontSize = 18.0 };
        textBlock.Inlines.Add(new Windows.UI.Xaml.Documents.Run { Text = "This text will not stick on text decoration." });

        TextBlock textBlockBad = new TextBlock
        {
            FontSize = 18.0,
            Text = "This text will not enable the TextDecorations to be turned off"
        };

与Typography.Capitals相同的行为

只需要对TextBlocks和RichTextBlocks使用内联就可以避免这些问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47894094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档