TextBlock下划线的问题

时间:2018-10-11 20:42:08

标签: uwp-xaml

我有下面的Xaml代码,试图根据布尔条件对文本块内容加下划线。当条件为true时,它按预期方式工作(可见下划线),但当条件为false时,下划线仍然存在(当下划线不可见)条件为假)

<TextBlock Text="Name" TextDecorations="{x:Bind Model.NameError, Converter={StaticResource TextUnderlineConverter}, Mode=OneWay}"

转换器代码

public class TextUnderlineConverter : IValueConverter
    {
public object Convert(object value, Type targetType, object parameter, string language)
        {
            if ((bool)value)
                return TextDecorations.Underline;
            else
               return TextDecorations.None;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }

2 个答案:

答案 0 :(得分:1)

@Venkat感谢您的反馈。这是一个已知问题。相关团队一直在调查此问题。

当前有一种解决方法,您可以为TextDecorations下的Run节点设置TextBlock

<TextBlock>
    <Run Text="Test Hello" TextDecorations="{x:Bind Flag, Converter={StaticResource ConverterText},Mode=OneWay}" />
</TextBlock>

答案 1 :(得分:0)

如下面的Xaml中所示,在UWP中显示错误:

            <TextBlock>
                <Run  Text="Decorations can be toggled on and off"/>
            </TextBlock>

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

如果您使用C#编写TextBlock,则会出现相同的问题

    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"
    };