TextBlock inlines and hit testing
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:
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?
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:
Code: Select all
<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>
Is it a bug or by design? Do you have any suggestions on how to avoid this?
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: TextBlock inlines and hit testing
This seems to be a bug, could you please report it in our bugtracker? Thanks!
Re: TextBlock inlines and hit testing
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!
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!
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: TextBlock inlines and hit testing
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