locked
can not get PointerEntered events for child controls

    Question

  • I have constructed a rather complex map GUI for a game. It is all built inside a Grid and in this grid i have put another grid that holds images with floor tiles, a canvas that holds items and a canvas that holds creatures. Each creature is put together in a grid with two images, the body and the head. I wold like to use the PointerEntered event to display information about the creatures when you hold the mouse pointer over them.

    My problem is that i can only get the PointerEntered event to trigger when i enter the grid that holds the map not for any control i put in the grid. I have tried with all the different layers and both the creature images and the grid that holds them. But it is still just the containing grid that reacts.

    Please help me!

    Saturday, June 14, 2014 2:10 PM

Answers

  • I tested with this code and had no issues:
     <Grid Background="Beige" Margin="50" PointerEntered="Grid_PointerEntered" x:Name="MainGrid">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid Margin="20" Grid.Column="0" Grid.Row="0" PointerEntered="Grid_PointerEntered" Background="White" x:Name="White"/>
            <Grid Margin="20" Grid.Column="1" Grid.Row="0" PointerEntered="Grid_PointerEntered" Background="Red" x:Name="Red"/>
            <Grid Margin="20" Grid.Column="2" Grid.Row="0" PointerEntered="Grid_PointerEntered" Background="Orange" x:Name="Orange"/>
            <Grid Margin="20" Grid.Column="0" Grid.Row="1" PointerEntered="Grid_PointerEntered" Background="Yellow" x:Name="Yellow"/>
            <Grid Margin="20" Grid.Column="1" Grid.Row="1" PointerEntered="Grid_PointerEntered" Background="Green" x:Name="Green"/>
            <Grid Margin="20" Grid.Column="2" Grid.Row="1" PointerEntered="Grid_PointerEntered" Background="Blue" x:Name="Blue"/>
            <Grid Margin="20" Grid.Column="0" Grid.Row="2" PointerEntered="Grid_PointerEntered" Background="Indigo" x:Name="Indigo"/>
            <Grid Margin="20" Grid.Column="1" Grid.Row="2" PointerEntered="Grid_PointerEntered" Background="Violet" x:Name="Violet"/>
            <Grid Margin="20" Grid.Column="2" Grid.Row="2" PointerEntered="Grid_PointerEntered" Background="Black" x:Name="Black"/>
        </Grid>
    private async void Grid_PointerEntered(object sender, PointerRoutedEventArgs e)
            {
                Grid ThisGrid = sender as Grid;
                Debug.WriteLine("The color of this grid is: " + ThisGrid.Name);
            }

    Can you show code that reproduces your specific issue?


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 16, 2014 12:38 PM
    Moderator

All replies

  • I tested with this code and had no issues:
     <Grid Background="Beige" Margin="50" PointerEntered="Grid_PointerEntered" x:Name="MainGrid">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Grid Margin="20" Grid.Column="0" Grid.Row="0" PointerEntered="Grid_PointerEntered" Background="White" x:Name="White"/>
            <Grid Margin="20" Grid.Column="1" Grid.Row="0" PointerEntered="Grid_PointerEntered" Background="Red" x:Name="Red"/>
            <Grid Margin="20" Grid.Column="2" Grid.Row="0" PointerEntered="Grid_PointerEntered" Background="Orange" x:Name="Orange"/>
            <Grid Margin="20" Grid.Column="0" Grid.Row="1" PointerEntered="Grid_PointerEntered" Background="Yellow" x:Name="Yellow"/>
            <Grid Margin="20" Grid.Column="1" Grid.Row="1" PointerEntered="Grid_PointerEntered" Background="Green" x:Name="Green"/>
            <Grid Margin="20" Grid.Column="2" Grid.Row="1" PointerEntered="Grid_PointerEntered" Background="Blue" x:Name="Blue"/>
            <Grid Margin="20" Grid.Column="0" Grid.Row="2" PointerEntered="Grid_PointerEntered" Background="Indigo" x:Name="Indigo"/>
            <Grid Margin="20" Grid.Column="1" Grid.Row="2" PointerEntered="Grid_PointerEntered" Background="Violet" x:Name="Violet"/>
            <Grid Margin="20" Grid.Column="2" Grid.Row="2" PointerEntered="Grid_PointerEntered" Background="Black" x:Name="Black"/>
        </Grid>
    private async void Grid_PointerEntered(object sender, PointerRoutedEventArgs e)
            {
                Grid ThisGrid = sender as Grid;
                Debug.WriteLine("The color of this grid is: " + ThisGrid.Name);
            }

    Can you show code that reproduces your specific issue?


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, June 16, 2014 12:38 PM
    Moderator
  • I checked again and realized that i had an image that covered the controls i was trying to access.

    My bad, sorry!

    Wednesday, June 18, 2014 10:41 AM