-
Notifications
You must be signed in to change notification settings - Fork 675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextRange not usable in XAML #9925
Comments
My workaround in the meantime is to derive a custom TextHighlighter. |
This is for further information on the use case and to provide the workaround. What I am trying to do is to highlight text in a rich text block based on a Match that was obtained from RegEx. The match is in an object that is being bound to a DataTemplate (specifically there is a Match property in the items in the ItemsSource of a ListView). Since this is in a DataTemplate, the Match has to be bound using Binding rather than x:Bind). The idea I mentioned above of deriving from TextHighlighter did not work because the Match cannot be bound to a property in the TextHighlighter-derived class, owing to the fact that TextHighlighter is not a DependencyObject. Another idea would be to derive from RichTextBlock and add a Match property, but this doesn't work because RichTextBlock is sealed. The solution is to use attached properties on the RichTextBlock to set the Match (and the Foreground and Background brushes). When the Match attached property is set, it sets the TextHighlighters property of the RichTextBlock. The point here is this is much too hard. One should be able to easily set the highlighting on a RichTextBlock using binding. The item class used in the ListView's ItemsSource looks something like this:
The DataTemplate for the ListView looks something like this:
And here are the attached properties:
|
Describe the bug
One can't use TextRange in XAML because StartIndex and Length are fields not properties. One also can't create a derived class having such properties, because it is sealed. This makes it very difficult to use TextRange in a XAML data template.
Steps to reproduce the bug
Create a ListView with a resource for the DataTemplate as shown in the screenshot. Observe that the StartIndex and Length cannot be assigned or bound.
Expected behavior
Should be able to use TextRange in XAML.
Screenshots
NuGet package version
None
Windows version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: