Files
Chat/ChatController/Core/BindableTextBlock.cs

32 lines
1.0 KiB
C#
Raw Normal View History

using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace ChatController.Core
{
public class BindableTextBlock : TextBlock
{
public ObservableCollection<Inline> InlineList
{
get => (ObservableCollection<Inline>) GetValue(InlineListProperty);
set => SetValue(InlineListProperty, value);
}
public static readonly DependencyProperty InlineListProperty = DependencyProperty.Register("InlineList", typeof(ObservableCollection<Inline>), 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<Inline>) e.NewValue);
}
}
}