Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting TextDecoration = None on TextBlock does not remove the strike through after applying it #1093

Closed
knightmeister opened this issue Jul 23, 2019 · 7 comments
Labels
area-TextBlocks TextBlock, RichTextBlock bug Something isn't working needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) team-Rendering Issue for the Rendering team
Milestone

Comments

@knightmeister
Copy link

Describe the bug
I am trying to strike through a TextBlock when the user taps it. This works great, but it's not possible to clear the strike through decoration once it's been applied.

Steps to reproduce the bug

  1. Add a TextBlock to a page
  2. Add a Tapped event
  3. Add the following code:
        private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var tb = (TextBlock)sender;
            if(tb.TextDecorations == Windows.UI.Text.TextDecorations.None)
            {
                tb.TextDecorations = Windows.UI.Text.TextDecorations.Strikethrough;
                tb.Foreground = new SolidColorBrush(Colors.Gray);
            }
            else
            {
                tb.TextDecorations = Windows.UI.Text.TextDecorations.None;
                tb.Foreground = new SolidColorBrush(Colors.Black);
            }
        }

Expected behavior
Tapping the TextBlock applies a strike through and changes the colour to gray. That works. Tapping it again should change the colour to black and remove the strike through. The colour changes but the strike through isn't removed.

Version Info
1903

NuGet package version:
N/A

Question
Is there a work around to this, because it's core for the UI I'm working on.

@msft-github-bot msft-github-bot added this to Needs triage in Controls Triage Jul 23, 2019
@mrlacey
Copy link
Contributor

mrlacey commented Jul 23, 2019

@knightmeister Yes, this totally looks like a bug in the TextBlock control. As a guess, I'd say it's not looking to do anything when the decoration is set to None, when it should also look to remove anything that's already there.

Fortunately, there's a simple workaround:

    private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
    {
        var tb = (TextBlock)sender;
        if (tb.TextDecorations == TextDecorations.None)
        {
            tb.TextDecorations = Windows.UI.Text.TextDecorations.Strikethrough;
            tb.Foreground = new SolidColorBrush(Colors.Gray);
        }
        else
        {
+           var text = tb.Text;
+           tb.Text = string.Empty;
            tb.TextDecorations = TextDecorations.None;
+           tb.Text = text;
            tb.Foreground = new SolidColorBrush(Colors.Black);
        }
    }

@YuliKl YuliKl added this to Needs triage in Rendering Triage via automation Jul 23, 2019
@YuliKl YuliKl removed this from Needs triage in Controls Triage Jul 23, 2019
@jevansaks jevansaks added area-TextBlocks TextBlock, RichTextBlock bug Something isn't working labels Jul 23, 2019
@codendone
Copy link
Contributor

Yes, this is an old bug. The TextDecoration property incorrectly does not mark the element as needing rendering when its value changed.

@codendone codendone moved this from Needs triage to Backlog in Rendering Triage Jul 24, 2019
@knightmeister
Copy link
Author

Thanks for the work around @mrlacey, works well.

@jevansaks jevansaks added the team-Rendering Issue for the Rendering team label Nov 7, 2019
@marcelwgn
Copy link
Contributor

I think this is something that can only be fixed with WinUI 3.

@tinodo
Copy link

tinodo commented Jun 16, 2023

Is there any ETA on a fix?
The workaround is nice, but not if the Text or Content and the TextDecoration are data-bound.
Something like this;
<TextBlock Text="{x:Bind sys:String.Format(x:Null, '{0} ({1}/{2})', Title, SuccessCount, FailureCount)}" TextDecorations="{x:Bind IsEnabled, Converter={StaticResource StrikethroughConverter}}" />

A more permanent fix would be great!

@c-npolyak
Copy link

It has not been fixed in WinUI3. Please fix it - should be a very easy fix and the bug is very nasty

@codendone codendone added the fixed-internally This bug has been fixed, and the fix will be shipped in the next version of WinUI 3. label Jun 28, 2023
@bpulliam bpulliam added this to the WinUI 3 in WinAppSDK 1.4 milestone Jul 7, 2023
@duncanmacmichael
Copy link
Member

Fixed in 1.4.0. @bpulliam please close this issue as I cannot :)

@bpulliam bpulliam removed the fixed-internally This bug has been fixed, and the fix will be shipped in the next version of WinUI 3. label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-TextBlocks TextBlock, RichTextBlock bug Something isn't working needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) team-Rendering Issue for the Rendering team
Projects
No open projects
Development

No branches or pull requests

9 participants