From 6154d0af46afb3a01b97e74a45919297cf782dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=AB=E5=9F=8Evia?= Date: Thu, 6 Jun 2024 22:52:48 +0800 Subject: [PATCH] 1.2.1.8 --- .../Panuon.WPF.UI/Helpers/TextBlockHelper.cs | 20 +++++++++++++++++-- .../Panuon.WPF.UI/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/SourceCode/SharedResources/Panuon.WPF.UI/Helpers/TextBlockHelper.cs b/SourceCode/SharedResources/Panuon.WPF.UI/Helpers/TextBlockHelper.cs index cf672fec..a33aa5ec 100644 --- a/SourceCode/SharedResources/Panuon.WPF.UI/Helpers/TextBlockHelper.cs +++ b/SourceCode/SharedResources/Panuon.WPF.UI/Helpers/TextBlockHelper.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; @@ -11,6 +12,21 @@ public static class TextBlockHelper { #region Properties + #region Text + public static string GetText(TextBlock textBlock) + { + return (string)textBlock.GetValue(TextProperty); + } + + public static void SetText(TextBlock textBlock, string value) + { + textBlock.SetValue(TextProperty, value); + } + + public static readonly DependencyProperty TextProperty = + DependencyProperty.RegisterAttached("Text", typeof(string), typeof(TextBlockHelper), new PropertyMetadata(OnHighlightTextChanged)); + #endregion + #region HighlightText public static string GetHighlightText(TextBlock textBlock) { @@ -97,7 +113,7 @@ private static void OnHighlightTextChanged(DependencyObject d, DependencyPropert { return; } - var text = textBlock.Text; + var text = GetText(textBlock); var regex = GetHighlightRegex(textBlock); var highlightText = GetHighlightText(textBlock); var foreground = GetHighlightForeground(textBlock); @@ -143,7 +159,7 @@ private static void OnHighlightTextChanged(DependencyObject d, DependencyPropert index = match.Index; matchText = match.Value; - if (string.IsNullOrEmpty(matchText) + if (string.IsNullOrEmpty(matchText) || rule == HighlightRule.FirstOnly) { textBlock.Inlines.Add(new Run(text)); diff --git a/SourceCode/SharedResources/Panuon.WPF.UI/Properties/AssemblyInfo.cs b/SourceCode/SharedResources/Panuon.WPF.UI/Properties/AssemblyInfo.cs index c5aad03c..e6742866 100644 --- a/SourceCode/SharedResources/Panuon.WPF.UI/Properties/AssemblyInfo.cs +++ b/SourceCode/SharedResources/Panuon.WPF.UI/Properties/AssemblyInfo.cs @@ -25,5 +25,5 @@ ResourceDictionaryLocation.SourceAssembly )] -[assembly: AssemblyVersion("1.2.1.7")] -[assembly: AssemblyFileVersion("1.2.1.7")] \ No newline at end of file +[assembly: AssemblyVersion("1.2.1.8")] +[assembly: AssemblyFileVersion("1.2.1.8")] \ No newline at end of file