DK.
DK.

Reputation: 3243

RichTextBlock hides its content when programmatically updated, twice

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:

<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.

Update 2018-12-11

Upvotes: 1

Views: 62

Answers (0)

Related Questions