using System.Collections.ObjectModel; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; namespace ChatController.Core { public class BindableTextBlock : TextBlock { public ObservableCollection InlineList { get => (ObservableCollection) GetValue(InlineListProperty); set => SetValue(InlineListProperty, value); } public static readonly DependencyProperty InlineListProperty = DependencyProperty.Register("InlineList", typeof(ObservableCollection), typeof(BindableTextBlock), new UIPropertyMetadata(null, OnPropertyChanged)); public static void OnPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { if(e.NewValue is null) { return; } var textBlock = (BindableTextBlock)sender; textBlock.Inlines.Clear(); textBlock.Inlines.AddRange((ObservableCollection) e.NewValue); } } }