├── HighlightSample
├── packages.config
├── App.config
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── App.xaml
├── App.xaml.cs
├── ViewModel.cs
├── MainWindow.xaml.cs
├── MainWindow.xaml
└── HighlightSample.csproj
├── HighlightableTextblock
├── HighlightableTextblock.nuspec
├── Properties
│ └── AssemblyInfo.cs
├── HighlightableTextblock.csproj
└── HighlightableTextBlock.cs
├── README.md
├── License.md
├── HighlightableTextblock.sln
├── .gitattributes
└── .gitignore
/HighlightSample/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/HighlightSample/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HighlightSample/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/HighlightSample/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/HighlightSample/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace HighlightSample
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/HighlightSample/ViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Prism.Mvvm;
7 |
8 | namespace HighlightSample
9 | {
10 | public class ViewModel : BindableBase
11 | {
12 | private string filter;
13 | private string fullText;
14 |
15 | public string Filter
16 | {
17 | get { return filter; }
18 | set { SetProperty(ref this.filter, value); }
19 | }
20 |
21 | public string FullText
22 | {
23 | get { return fullText; }
24 | set { SetProperty(ref this.fullText, value); }
25 | }
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/HighlightableTextblock/HighlightableTextblock.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | HighlightableTextBlock
5 | $version$
6 | $title$
7 | Kevin Hsu
8 | Kevin Hsu
9 | https://github.com/kthsu/HighlightableTextblock/blob/master/License.md
10 | https://github.com/kthsu/HighlightableTextblock
11 | false
12 | Awesome highlighting add-on for WPF TextBlock
13 | Initial Release
14 | Copyright 2016
15 | wpf highlight textblock text xaml
16 |
17 |
--------------------------------------------------------------------------------
/HighlightSample/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace HighlightSample
17 | {
18 | ///
19 | /// Interaction logic for MainWindow.xaml
20 | ///
21 | public partial class MainWindow : Window
22 | {
23 | public MainWindow()
24 | {
25 | InitializeComponent();
26 | DataContext = new ViewModel();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HighlightableTextBlock - Highlighting add-on for WPF TextBlock
2 |
3 | ## Quick Start
4 | ### Modifying the XAML file
5 |
6 | After installing HighlightableTextBlock:
7 |
8 | * Open up the xaml file containing the TextBlock you wish to add highlighting.
9 | * Add this namespace reference to the XAML:
10 |
11 | xmlns:controls="clr-namespace:HighlightableTextBlock;assembly=HighlightableTextBlock"
12 | * Locate the TextBlock declaration in the XAML.
13 | * Add this attribute:
14 |
15 | controls:HighlightableTextBlock.HightlightText="{Binding SearchText}"
16 |
17 | * Ta-da! Now you have highlightable TextBlocks in your application!
18 | * Customization:
19 |
20 | * Highlight color - controls:HighlightableTextBlock.HighlightBrush="Yellow"
21 | * Highlight text color - controls:HighlightableTextBlock.HighlightTextBrush="Red"
22 | * Bold - controls:HighlightableTextBlock.Bold="True"
23 | * Italic - controls:HighlightableTextBlock.Italic="True"
24 | * Underline - controls:HighlightableTextBlock.Underline="True"
25 |
--------------------------------------------------------------------------------
/License.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Kevin Hsu
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/HighlightSample/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace HighlightSample.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/HighlightableTextblock/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("HighlightableTextBlock")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("HighlightableTextBlock")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("db861ed0-c4b8-4bd5-b51d-8d055a8d7ee7")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.1.1")]
36 | [assembly: AssemblyFileVersion("1.0.1.1")]
37 |
--------------------------------------------------------------------------------
/HighlightableTextblock.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HighlightSample", "HighlightSample\HighlightSample.csproj", "{648794A4-8575-449F-A10A-AF03DE83019A}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HighlightableTextBlock", "HighlightableTextBlock\HighlightableTextBlock.csproj", "{DB861ED0-C4B8-4BD5-B51D-8D055A8D7EE7}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {648794A4-8575-449F-A10A-AF03DE83019A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {648794A4-8575-449F-A10A-AF03DE83019A}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {648794A4-8575-449F-A10A-AF03DE83019A}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {648794A4-8575-449F-A10A-AF03DE83019A}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {DB861ED0-C4B8-4BD5-B51D-8D055A8D7EE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {DB861ED0-C4B8-4BD5-B51D-8D055A8D7EE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {DB861ED0-C4B8-4BD5-B51D-8D055A8D7EE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {DB861ED0-C4B8-4BD5-B51D-8D055A8D7EE7}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/HighlightSample/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/HighlightSample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("HighlightableTextblock")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("HighlightableTextblock")]
15 | [assembly: AssemblyCopyright("Copyright © 2016")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/HighlightSample/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace HighlightSample.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("HighlightSample.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/HighlightableTextblock/HighlightableTextblock.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {DB861ED0-C4B8-4BD5-B51D-8D055A8D7EE7}
8 | Library
9 | Properties
10 | HighlightableTextBlock
11 | HighlightableTextBlock
12 | v4.5.2
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 | true
34 |
35 |
36 | highlightableTextBlock.pfx
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
67 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | [Xx]64/
19 | [Xx]86/
20 | [Bb]uild/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 |
85 | # Visual Studio profiler
86 | *.psess
87 | *.vsp
88 | *.vspx
89 | *.sap
90 |
91 | # TFS 2012 Local Workspace
92 | $tf/
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 | *.DotSettings.user
101 |
102 | # JustCode is a .NET coding add-in
103 | .JustCode
104 |
105 | # TeamCity is a build add-in
106 | _TeamCity*
107 |
108 | # DotCover is a Code Coverage Tool
109 | *.dotCover
110 |
111 | # NCrunch
112 | _NCrunch_*
113 | .*crunch*.local.xml
114 | nCrunchTemp_*
115 |
116 | # MightyMoose
117 | *.mm.*
118 | AutoTest.Net/
119 |
120 | # Web workbench (sass)
121 | .sass-cache/
122 |
123 | # Installshield output folder
124 | [Ee]xpress/
125 |
126 | # DocProject is a documentation generator add-in
127 | DocProject/buildhelp/
128 | DocProject/Help/*.HxT
129 | DocProject/Help/*.HxC
130 | DocProject/Help/*.hhc
131 | DocProject/Help/*.hhk
132 | DocProject/Help/*.hhp
133 | DocProject/Help/Html2
134 | DocProject/Help/html
135 |
136 | # Click-Once directory
137 | publish/
138 |
139 | # Publish Web Output
140 | *.[Pp]ublish.xml
141 | *.azurePubxml
142 |
143 | # TODO: Un-comment the next line if you do not want to checkin
144 | # your web deploy settings because they may include unencrypted
145 | # passwords
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # NuGet Packages
150 | *.nupkg
151 | # The packages folder can be ignored because of Package Restore
152 | **/packages/*
153 | # except build/, which is used as an MSBuild target.
154 | !**/packages/build/
155 | # Uncomment if necessary however generally it will be regenerated when needed
156 | #!**/packages/repositories.config
157 | # NuGet v3's project.json files produces more ignoreable files
158 | *.nuget.props
159 | *.nuget.targets
160 |
161 | # Microsoft Azure Build Output
162 | csx/
163 | *.build.csdef
164 |
165 | # Microsoft Azure Emulator
166 | ecf/
167 | rcf/
168 |
169 | # Microsoft Azure ApplicationInsights config file
170 | ApplicationInsights.config
171 |
172 | # Windows Store app package directory
173 | AppPackages/
174 | BundleArtifacts/
175 |
176 | # Visual Studio cache files
177 | # files ending in .cache can be ignored
178 | *.[Cc]ache
179 | # but keep track of directories ending in .cache
180 | !*.[Cc]ache/
181 |
182 | # Others
183 | ClientBin/
184 | [Ss]tyle[Cc]op.*
185 | ~$*
186 | *~
187 | *.dbmdl
188 | *.dbproj.schemaview
189 | *.pfx
190 | *.publishsettings
191 | node_modules/
192 | orleans.codegen.cs
193 |
194 | # RIA/Silverlight projects
195 | Generated_Code/
196 |
197 | # Backup & report files from converting an old project file
198 | # to a newer Visual Studio version. Backup files are not needed,
199 | # because we have git ;-)
200 | _UpgradeReport_Files/
201 | Backup*/
202 | UpgradeLog*.XML
203 | UpgradeLog*.htm
204 |
205 | # SQL Server files
206 | *.mdf
207 | *.ldf
208 |
209 | # Business Intelligence projects
210 | *.rdl.data
211 | *.bim.layout
212 | *.bim_*.settings
213 |
214 | # Microsoft Fakes
215 | FakesAssemblies/
216 |
217 | # GhostDoc plugin setting file
218 | *.GhostDoc.xml
219 |
220 | # Node.js Tools for Visual Studio
221 | .ntvs_analysis.dat
222 |
223 | # Visual Studio 6 build log
224 | *.plg
225 |
226 | # Visual Studio 6 workspace options file
227 | *.opt
228 |
229 | # Visual Studio LightSwitch build output
230 | **/*.HTMLClient/GeneratedArtifacts
231 | **/*.DesktopClient/GeneratedArtifacts
232 | **/*.DesktopClient/ModelManifest.xml
233 | **/*.Server/GeneratedArtifacts
234 | **/*.Server/ModelManifest.xml
235 | _Pvt_Extensions
236 |
237 | # LightSwitch generated files
238 | GeneratedArtifacts/
239 | ModelManifest.xml
240 |
241 | # Paket dependency manager
242 | .paket/paket.exe
243 |
244 | # FAKE - F# Make
245 | .fake/
--------------------------------------------------------------------------------
/HighlightSample/HighlightSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {648794A4-8575-449F-A10A-AF03DE83019A}
8 | WinExe
9 | Properties
10 | HighlightSample
11 | HighlightSample
12 | v4.5.2
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 | true
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 | ..\packages\Prism.Core.6.2.0\lib\net45\Prism.dll
40 | True
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | 4.0
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | MSBuild:Compile
60 | Designer
61 |
62 |
63 |
64 | MSBuild:Compile
65 | Designer
66 |
67 |
68 | App.xaml
69 | Code
70 |
71 |
72 | MainWindow.xaml
73 | Code
74 |
75 |
76 |
77 |
78 | Code
79 |
80 |
81 | True
82 | True
83 | Resources.resx
84 |
85 |
86 | True
87 | Settings.settings
88 | True
89 |
90 |
91 | ResXFileCodeGenerator
92 | Resources.Designer.cs
93 |
94 |
95 |
96 | SettingsSingleFileGenerator
97 | Settings.Designer.cs
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | {db861ed0-c4b8-4bd5-b51d-8d055a8d7ee7}
107 | HighlightableTextBlock
108 |
109 |
110 |
111 |
118 |
--------------------------------------------------------------------------------
/HighlightSample/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/HighlightableTextblock/HighlightableTextBlock.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Text.RegularExpressions;
4 | using System.Windows;
5 | using System.Windows.Controls;
6 | using System.Windows.Documents;
7 | using System.Windows.Media;
8 |
9 | namespace HighlightableTextBlock
10 | {
11 | public class HighlightableTextBlock
12 | {
13 | #region Bold
14 |
15 | public static bool GetBold(DependencyObject obj)
16 | {
17 | return (bool)obj.GetValue(BoldProperty);
18 | }
19 |
20 | public static void SetBold(DependencyObject obj, bool value)
21 | {
22 | obj.SetValue(BoldProperty, value);
23 | }
24 |
25 | // Using a DependencyProperty as the backing store for Bold. This enables animation, styling, binding, etc...
26 | public static readonly DependencyProperty BoldProperty =
27 | DependencyProperty.RegisterAttached("Bold", typeof(bool), typeof(HighlightableTextBlock), new PropertyMetadata(false, Refresh));
28 |
29 | #endregion
30 |
31 | #region Italic
32 |
33 | public static bool GetItalic(DependencyObject obj)
34 | {
35 | return (bool)obj.GetValue(ItalicProperty);
36 | }
37 |
38 | public static void SetItalic(DependencyObject obj, bool value)
39 | {
40 | obj.SetValue(ItalicProperty, value);
41 | }
42 |
43 | // Using a DependencyProperty as the backing store for Italic. This enables animation, styling, binding, etc...
44 | public static readonly DependencyProperty ItalicProperty =
45 | DependencyProperty.RegisterAttached("Italic", typeof(bool), typeof(HighlightableTextBlock), new PropertyMetadata(false, Refresh));
46 |
47 | #endregion
48 |
49 | #region Underline
50 |
51 | public static bool GetUnderline(DependencyObject obj)
52 | {
53 | return (bool)obj.GetValue(UnderlineProperty);
54 | }
55 |
56 | public static void SetUnderline(DependencyObject obj, bool value)
57 | {
58 | obj.SetValue(UnderlineProperty, value);
59 | }
60 |
61 | // Using a DependencyProperty as the backing store for Underline. This enables animation, styling, binding, etc...
62 | public static readonly DependencyProperty UnderlineProperty =
63 | DependencyProperty.RegisterAttached("Underline", typeof(bool), typeof(HighlightableTextBlock), new PropertyMetadata(false, Refresh));
64 |
65 | #endregion
66 |
67 | #region HighlightTextBrush
68 |
69 | public static Brush GetHighlightTextBrush(DependencyObject obj)
70 | {
71 | return (Brush)obj.GetValue(HighlightTextBrushProperty);
72 | }
73 |
74 | public static void SetHighlightTextBrush(DependencyObject obj, Brush value)
75 | {
76 | obj.SetValue(HighlightTextBrushProperty, value);
77 | }
78 |
79 | // Using a DependencyProperty as the backing store for HighlightTextBrush. This enables animation, styling, binding, etc...
80 | public static readonly DependencyProperty HighlightTextBrushProperty =
81 | DependencyProperty.RegisterAttached("HighlightTextBrush", typeof(Brush), typeof(HighlightableTextBlock), new PropertyMetadata(SystemColors.HighlightTextBrush, Refresh));
82 |
83 | #endregion
84 |
85 | #region HighlightBrush
86 |
87 | public static Brush GetHighlightBrush(DependencyObject obj)
88 | {
89 | return (Brush)obj.GetValue(HighlightBrushProperty);
90 | }
91 |
92 | public static void SetHighlightBrush(DependencyObject obj, Brush value)
93 | {
94 | obj.SetValue(HighlightBrushProperty, value);
95 | }
96 |
97 | // Using a DependencyProperty as the backing store for HighlightBrush. This enables animation, styling, binding, etc...
98 | public static readonly DependencyProperty HighlightBrushProperty =
99 | DependencyProperty.RegisterAttached("HighlightBrush", typeof(Brush), typeof(HighlightableTextBlock), new PropertyMetadata(SystemColors.HighlightBrush, Refresh));
100 |
101 | #endregion
102 |
103 | #region HighlightText
104 |
105 | public static string GetHightlightText(DependencyObject obj)
106 | {
107 | return (string)obj.GetValue(HightlightTextProperty);
108 | }
109 |
110 | public static void SetHightlightText(DependencyObject obj, string value)
111 | {
112 | obj.SetValue(HightlightTextProperty, value);
113 | }
114 |
115 | // Using a DependencyProperty as the backing store for HightlightText. This enables animation, styling, binding, etc...
116 | public static readonly DependencyProperty HightlightTextProperty =
117 | DependencyProperty.RegisterAttached("HightlightText", typeof(string), typeof(HighlightableTextBlock), new PropertyMetadata(string.Empty, Refresh));
118 |
119 | #endregion
120 |
121 | #region InternalText
122 |
123 | protected static string GetInternalText(DependencyObject obj)
124 | {
125 | return (string)obj.GetValue(InternalTextProperty);
126 | }
127 |
128 | protected static void SetInternalText(DependencyObject obj, string value)
129 | {
130 | obj.SetValue(InternalTextProperty, value);
131 | }
132 |
133 | // Using a DependencyProperty as the backing store for InternalText. This enables animation, styling, binding, etc...
134 | protected static readonly DependencyProperty InternalTextProperty =
135 | DependencyProperty.RegisterAttached("InternalText", typeof(string),
136 | typeof(HighlightableTextBlock), new PropertyMetadata(string.Empty, OnInternalTextChanged));
137 |
138 | private static void OnInternalTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
139 | {
140 | var textblock = d as TextBlock;
141 |
142 | if (textblock != null)
143 | {
144 | textblock.Text = e.NewValue as string;
145 | Highlight(textblock);
146 | }
147 | }
148 |
149 | #endregion
150 |
151 | #region IsBusy
152 |
153 | private static bool GetIsBusy(DependencyObject obj)
154 | {
155 | return (bool)obj.GetValue(IsBusyProperty);
156 | }
157 |
158 | private static void SetIsBusy(DependencyObject obj, bool value)
159 | {
160 | obj.SetValue(IsBusyProperty, value);
161 | }
162 |
163 | // Using a DependencyProperty as the backing store for IsBusy. This enables animation, styling, binding, etc...
164 | private static readonly DependencyProperty IsBusyProperty =
165 | DependencyProperty.RegisterAttached("IsBusy", typeof(bool), typeof(HighlightableTextBlock), new PropertyMetadata(false));
166 |
167 | #endregion
168 |
169 | #region Methods
170 |
171 | private static void Refresh(DependencyObject d, DependencyPropertyChangedEventArgs e)
172 | {
173 | Highlight(d as TextBlock);
174 | }
175 |
176 | private static void Highlight(TextBlock textblock)
177 | {
178 | if (textblock == null) return;
179 |
180 | string text = textblock.Text;
181 |
182 | if (textblock.GetBindingExpression(HighlightableTextBlock.InternalTextProperty) == null)
183 | {
184 | var textBinding = textblock.GetBindingExpression(TextBlock.TextProperty);
185 |
186 | if (textBinding != null)
187 | {
188 | textblock.SetBinding(HighlightableTextBlock.InternalTextProperty, textBinding.ParentBindingBase);
189 |
190 | var propertyDescriptor = DependencyPropertyDescriptor.FromProperty(TextBlock.TextProperty, typeof(TextBlock));
191 |
192 | propertyDescriptor.RemoveValueChanged(textblock, OnTextChanged);
193 | }
194 | else
195 | {
196 | var propertyDescriptor = DependencyPropertyDescriptor.FromProperty(TextBlock.TextProperty, typeof(TextBlock));
197 |
198 | propertyDescriptor.AddValueChanged(textblock, OnTextChanged);
199 |
200 | textblock.Unloaded -= Textblock_Unloaded;
201 | textblock.Unloaded += Textblock_Unloaded;
202 | }
203 | }
204 |
205 | if (!String.IsNullOrEmpty(text))
206 | {
207 | SetIsBusy(textblock, true);
208 |
209 | var toHighlight = GetHightlightText(textblock);
210 |
211 | if (!String.IsNullOrEmpty(toHighlight))
212 | {
213 | var matches = Regex.Split(text, String.Format("({0})", Regex.Escape(toHighlight)), RegexOptions.IgnoreCase);
214 |
215 | textblock.Inlines.Clear();
216 |
217 | var highlightBrush = GetHighlightBrush(textblock);
218 | var highlightTextBrush = GetHighlightTextBrush(textblock);
219 |
220 | foreach (var subString in matches)
221 | {
222 | if (String.Compare(subString, toHighlight, true) == 0)
223 | {
224 | var formattedText = new Run(subString)
225 | {
226 | Background = highlightBrush,
227 | Foreground = highlightTextBrush,
228 | };
229 |
230 | if (GetBold(textblock))
231 | {
232 | formattedText.FontWeight = FontWeights.Bold;
233 | }
234 |
235 | if (GetItalic(textblock))
236 | {
237 | formattedText.FontStyle = FontStyles.Italic;
238 | }
239 |
240 | if (GetUnderline(textblock))
241 | {
242 | formattedText.TextDecorations.Add(TextDecorations.Underline);
243 | }
244 |
245 | textblock.Inlines.Add(formattedText);
246 | }
247 | else
248 | {
249 | textblock.Inlines.Add(subString);
250 | }
251 | }
252 | }
253 | else
254 | {
255 | textblock.Inlines.Clear();
256 | textblock.SetCurrentValue(TextBlock.TextProperty, text);
257 | }
258 |
259 | SetIsBusy(textblock, false);
260 | }
261 | }
262 |
263 | private static void Textblock_Unloaded(object sender, RoutedEventArgs e)
264 | {
265 | var propertyDescriptor = DependencyPropertyDescriptor.FromProperty(TextBlock.TextProperty, typeof(TextBlock));
266 |
267 | propertyDescriptor.RemoveValueChanged(sender as TextBlock, OnTextChanged);
268 | }
269 |
270 | private static void OnTextChanged(object sender, EventArgs e)
271 | {
272 | var textBlock = sender as TextBlock;
273 |
274 | if (textBlock != null &&
275 | !GetIsBusy(textBlock))
276 | {
277 | Highlight(textBlock);
278 | }
279 | }
280 |
281 | #endregion
282 | }
283 | }
284 |
--------------------------------------------------------------------------------