Unplanned
Last Updated: 25 Dec 2025 08:29 by ADMIN
Sam
Created on: 16 Dec 2025 08:59
Category: HighlightTextBlock
Type: Bug Report
1
RadHighlightTextBlock — Text binding stops updating when HighlightText is used

RadHighlightTextBlock — Text binding stops updating when HighlightText is used

.Net framework 4.7.2
Telerik WPF Version 2025.1.211.462

Detailed Information

When developing an application using Telerik's RadHighlightTextBlock control, I encountered the following issues:

When attempting to dynamically update the control's `Text` and `HighlightText` properties through data binding, the control fails to display the updated content correctly. Specifically:

  1. After updating property values in the ViewModel, RadHighlightTextBlock doesn't display the new text content
  2. Even if the text updates, the highlighted portion doesn't correctly reflect the new HighlightText value
  3. The control's UI display is inconsistent with the actual values in the data model

I have confirmed that:

  • Data binding paths are correct
  • ViewModel implements INotifyPropertyChanged
  • Other controls bound to the same data source update correctly

I suspect this might be an issue with RadHighlightTextBlock's internal update handling mechanism, or it may require specific settings to properly handle dynamic update scenarios.

My Code:

MainWindow.xaml

<Window x:Class="RadHighlightTextBlock_Issue.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:RadHighlightTextBlock_Issue"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <local:MyViewModel x:Key="MyViewModel"/>
    </Window.Resources>
    <StackPanel>
        <telerik:RadHighlightTextBlock x:Name="highlightTextBlock" 
                                       Text="{Binding Source={StaticResource MyViewModel}, Path=SelectedItem.Description}"
                                      HighlightText="{Binding Source={StaticResource MyViewModel}, Path=SelectedItem.HighlightText}"
                                      HighlightForeground="Red"
                                      HighlightBackground="Yellow"
                                      FontSize="16"
                                      Margin="10"/>
        <telerik:RadButton Content="Content0" Command="{Binding Source={StaticResource MyViewModel}, Path=C0Command}"/>
        <telerik:RadButton Content="Content1" Command="{Binding Source={StaticResource MyViewModel}, Path=C1Command}"/>
    </StackPanel>
</Window>

MainWindow.xaml.cs

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Input;

namespace RadHighlightTextBlock_Issue
{
    /// <summary>
    /// MainWindow.xaml 的互動邏輯
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void RadButton_Click(object sender, RoutedEventArgs e)
        {
            highlightTextBlock.Text = "This is a sample text to demonstrate the RadHighlightTextBlock control.";
        }

        private void RadButton_Click_1(object sender, RoutedEventArgs e)
        {
            highlightTextBlock.Text = "This is another sample text for the second button.";
        }
    }

    public class MyViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<DataItem> Items { get; set; }
        public MyViewModel()
        {
            Items = new ObservableCollection<DataItem>
            {
                new DataItem { HighlightText = "sample", Description = "This is a sample description." },
                new DataItem { HighlightText = "second", Description = "This is the second item description." },
                new DataItem { HighlightText = "text", Description = "This item contains the word text." }
            };

            SelectedItem = Items.FirstOrDefault();
        }

        public ICommand C0Command => new RelayCommand<object>((obj) =>
        {
            SelectedItem = Items.FirstOrDefault();
        });

        public ICommand C1Command => new RelayCommand<object>((obj) =>
        {
            SelectedItem = Items.LastOrDefault();
        });

        private DataItem _selectedItem;
        public DataItem SelectedItem
        {
            get { return _selectedItem; }
            set
            {
                if (_selectedItem != value)
                {
                    _selectedItem = value;
                    OnPropertyChanged();
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    public class DataItem
    {
        public string HighlightText { get; set; }
        public string Description { get; set; }
    }

    /*Implement RelayCommand...*/
}

Has anyone encountered a similar issue? Is there any way to resolve it?
Thank you all.

3 comments
ADMIN
Martin Ivanov
Posted on: 25 Dec 2025 08:29

Hello Sam,

This seems to be a bug in the internal logic of the component so I've changed the status of this report.

About your question, yes, as most WPF properties the default binding mode of the Text property of TextBlock is set to OneWay. Setting it to TwoWay in the suggested workaround slightly changes the value setting priorities and the execution timing of the internally defined property changed callbacks for Text and HighlightedText.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Sam
Posted on: 23 Dec 2025 09:38

Thank you, it works properly now.

Additionally, I would like to ask a question: In the MVVM design pattern, isn't the Mode for TextBlock generally set to OneWay? Why is it set to TwoWay here?

ADMIN
Martin Ivanov
Posted on: 22 Dec 2025 16:05

Hello Sam,

I am investigating this and will get back to you when I have more information.

In the meantime, you can work this around by changing the binding mode to TwoWay.

<telerik:RadHighlightTextBlock x:Name="highlightTextBlock" 
                                       Text="{Binding Source={StaticResource MyViewModel}, Path=SelectedItem.Description, Mode=TwoWay}"
                                      HighlightText="{Binding Source={StaticResource MyViewModel}, Path=SelectedItem.HighlightText, Mode=TwoWay}"
                                      HighlightForeground="Red"
                                      HighlightBackground="Yellow"
                                      FontSize="16"
                                      Margin="10"/>

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.