0

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?

Merve Sahin
  • 1,008
  • 2
  • 14
  • 26

3 Answers3

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

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
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