When I move a label over a Rectangle, I want the rectangle to trigger a mouseEnter
event, it is not working because the Label overlaps the Rectangle. I tried with isHitTestVisible = false
, but then I couldn't move the label. Is there a way to do this?
Asked
Active
Viewed 2,398 times
0

Merve Sahin
- 1,008
- 2
- 14
- 26
3 Answers
0
I used a border because, if I recall correctly, it's the only way it can be done.
WINDOW.RESOURCES
<Style TargetType="{x:Type Border}">
<Setter Property="Background" Value="White"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#FFE6E6E6"/>
</Trigger>
</Style.Triggers>
</Style>
GRID
<Border BorderBrush="#FF000000" BorderThickness="0,0,3,3" Grid.Row="0" Grid.Column="0">
<Image Name="x0y0" Source="/Tictactoe;component/image/null-black.png"/>
</Border>
I hope I grabbed the right stuff for you. :p
-
unfortunately it's not working when I hover with a label over it – Merve Sahin Mar 27 '16 at 22:19
-
Sorry dude. I thought it might have been useful. – Mar 27 '16 at 22:48
0
Is this what you're looking for? `
<Grid>
<Rectangle x:Name="rect" Fill="{Binding ElementName=label, Path=Background}" />
<TextBlock x:Name="label" Text="Hover over me" >
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Height" Value="20" />
<Setter Property="Width" Value="100" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightBlue" />
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Grid>
`

Jace
- 777
- 1
- 5
- 18
-
no it's not what I'm trying to do.. I think my question was not clear enough, I edited it. – Merve Sahin Mar 28 '16 at 00:03
0
This is how I achieve this kind of effect with my DataGridRow Objects. Maybe it can help.
<EventTrigger RoutedEvent="DataGridRow.DragEnter">
<BeginStoryboard x:Name="DragEnterStoryboard">
<Storyboard>
<ColorAnimation
Storyboard.TargetProperty="Background.Color"
To="{StaticResource PartEntityDragEnterBackgroundColor}"
Duration="0:0:0.25"/>
<ColorAnimation
Storyboard.TargetProperty="Foreground.Color"
To="{StaticResource PartEntityDragEnterForegroundColor}"
Duration="0:0:0.25"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>

Jace
- 777
- 1
- 5
- 18
-
this has not worked either.. Somehow the mouseenter event is not being triggered when the mouse is moving a UIElement. – Merve Sahin Mar 28 '16 at 15:51
-
-