AnKor
Topic Author
Posts: 35
Joined: 22 Jul 2022, 16:14

TextBlock inlines and hit testing

15 Feb 2025, 23:17

It appears VisualTreeHelper::HitTest may return TextElement inlines from a TextBlock. I can see how this may be an useful feature, but this isn't the case in WPF.

This behavior leads to a couple of issues.
First, I can't simply traverse the visual tree upwards via VisualTreeHelper::GetParent, because it returns null for a TextElement. I noticed it long ago, but it didn't bother me much because it is easy to work around.
However the second one is worse: IsMouseOver triggers still work on a disabled element if the mouse happens to be over a text contained in an inline.
It can be easily reproduced in XamlToy:
		<TextBlock Width="400" Height="200" IsEnabled="False">
			<Span Foreground="White" FontSize="50">Mouse over text</Span>
			<TextBlock.Style>
				<Style TargetType="TextBlock">
					<Setter Property="Background" Value="Green"/>
					<Style.Triggers>
						<Trigger Property="IsMouseOver" Value="True">
							<Setter Property="Background" Value="Blue"/>
						</Trigger>
					</Style.Triggers>
				</Style>
			</TextBlock.Style>
		</TextBlock>
The block changes color to blue in Noesis when I move the mouse over text, but doesn't do so in WPF.
Is it a bug or by design? Do you have any suggestions on how to avoid this?
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: TextBlock inlines and hit testing

17 Feb 2025, 19:36

This seems to be a bug, could you please report it in our bugtracker? Thanks!
 
AnKor
Topic Author
Posts: 35
Joined: 22 Jul 2022, 16:14

Re: TextBlock inlines and hit testing

17 Feb 2025, 21:44

Created #3969.
I'm not sure whether both issues are related or if there are anything else I missed. As I mentioned I'm more concerned about the IsEnabled one.

Thanks!
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: TextBlock inlines and hit testing

19 Feb 2025, 11:25

Thanks for the report, I might know what is happening. Will fix the IsEnabled issue for the next release.

Who is online

Users browsing this forum: No registered users and 7 guests