Does PointerEntered work for WinUI?

Hong 1,206 Reputation points
2024-01-27T00:45:15.5966667+00:00

I have tried all kinds of things to make PointerEntered work to no avail. Xaml:

    <Border
       BorderThickness="5"
       BorderBrush="Yellow"
       Width="300"
       Height="300"
       HorizontalAlignment="Center"
       VerticalAlignment="Center"
       Background="AliceBlue"
       PointerEntered="PointerEntered"
       PointerExited="PointerExited">
    </Border>


Code behind:

    private void PointerEntered(object sender, PointerRoutedEventArgs e)
    {
        tbInformation.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
    }

    private void PointerExited(object sender, PointerRoutedEventArgs e)
    {
        tbInformation.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
    }

The events are not fired at all no matter how I move and where I put the mouse cursor. Could anyone shed some light on this?

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
745 questions
{count} votes

Accepted answer
  1. gekka 7,911 Reputation points MVP
    2024-01-27T02:15:07.98+00:00

    I tried with a simple window and the event did occur.

    <Window
        x:Class="CSWinUI3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:CSWinUI3"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
    <Grid>
        <Border
           BorderThickness="5"
           BorderBrush="Yellow"
           Width="300"
           Height="300"
           HorizontalAlignment="Center"
           VerticalAlignment="Center"
           Background="AliceBlue"
           PointerEntered="PointerEntered"
           PointerExited="PointerExited">
            </Border>
        </Grid>
    </Window>
    

    However, if IsHitVisible is false on the ancestor element, the event may not fire.

    <Grid IsHitTestVisible="False">
        <Border
    
    2 people found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful