While working on a small UWP application that displays rich text and updates portions of it based on model changes, I've stumbled upon a really strange RichTextBlock
bug. I'd appreciate if someone could provide an insight on this RichTextBlock
peculiarity or give an idea on fixing this.
Here is a simplified reproduction code and bug's use case:
RichTextBlock
with code-updated content works just fine until user clicks on it. After the click it displays one more change, but on the 2nd change the content becomes hidden.After that, if user selects something in the now invisible text or presses Ctr+A the
RichTextBlock
would re-display it's content, but on the 2nd text change after that the content becomes hidden again.What's curious, using the "Do Nothing" button makes content permanently appear, although clicking on the
RichTextBlock
once more makes it disappear again.
<Page
x:Class="RichTextBlockTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Viewbox>
<StackPanel Spacing="8" Margin="4">
<RichTextBlock FontSize="24">
<Paragraph>
<Run x:Name="timeRun">{ Time is Now }</Run>
</Paragraph>
</RichTextBlock>
<Button HorizontalAlignment="Stretch">Do Nothing</Button>
</StackPanel>
</Viewbox>
</Page>
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace RichTextBlockTest
{
public sealed partial class MainPage : Page
{
private DispatcherTimer timer =
new DispatcherTimer { Interval = new TimeSpan(0, 0, 1) };
public MainPage()
{
InitializeComponent();
timer.Tick += (o, e) =>
{
timeRun.Text = DateTime.Now.ToString("HH:mm:ss");
};
timer.Start();
}
}
}
Besides the above, I've tried this scenario with binding, DependencyProperty
, {x:Bind}
and also with re-creating the Run
and the Paragraph
there instead of directly changing Run.Text
from the code - all with the same result.
- The project is targeting Windows 10, version 1803 (10.0; Build 17134)
- Confirmed this bug on 2 boxes running Win 10 Pro 1803 - development and another clean test machine.
- Note that Windows 10 Pro 1809 and a Server build 1809 don't show this bug (the project was still targeting 1803 when tested). There are some quirks how
RichTextBlock
displays text when user selects a portion of it while the text is modified including temporary disappearance similar to the bug above, but in 1809 a) disappearance is not permanent and requires not just a click, but a selection in progress, b) it's a gray area how the control should behave if user-selected text was modified by the application mid-flight, and c) there are easy and logical workarounds there, e.g. pause automatic text changes if user tries to select something.
Update 2018-12-11
- VS.Net was updated to 15.9.4 that also required projects targeting 1803 downgrade(!)
Microsoft.NETCore.UniversalWindowsPlatform
version from 6.2.2 down to 6.1.9. The bug is still reproducible in Windows 10 Pro 1803.