Forum Xamarin.Forms

VisualElement should get IsMouseOver property


It should be possible to style VisualElement with triggers for hover and handle hover events.

API Changes

Analog to System.Windows.UIElement, the class VisualElement should get an IsMouseOver dependency property, an MouseEnter and an MouseLeave event.

  • the IsMouseOver property should get set to True after MouseEnter fired.
  • the IsMouseOver property should get set to False after MouseLeave fired.
  • analog to the MouseEventArgs, the argument of the events should provide

    • the id and type of the input device
    • mouse/pen button states
    • distance of the pen from the display, or zero if it is a mouse
  • in case the device doesn't support mouse or pen input, the events should never fire and hover should stay on False

The property may be called 'IsHovered', since the input device may not be a mouse.

Intended Use Case

It should be possible to redesign an visual element based on hover state:

    <Style x:Key="PrimaryButton" TargetType="Button">
        <Setter Property="FontAttributes" Value="Bold" />
        <Setter Property="TextColor" Value="White" />
        <Setter Property="BackgroundColor" Value="{StaticResource Grey500}" />
            <Trigger TargetType="Button" Property="IsMouseOver" Value="True">
                <Setter Property="TextColor" Value="White" />

The events may ie. be used for presenting a custom cursor when hovering, like when previewing the brush in an painting application.


Rejected · Last Updated

We are not currently looking to add mouse hover states as this opens a far larger can of worms. Realistically a proposal attempting to tackle this would need to tackle Prelight and keyboard focus at the same time as these API's are deeply related.


  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    the main usage for XF is to be used on mobile, where there's no concept of mouse or mouseOver as I could have my finger wherever I want not on the screen, or have multiple fingers at the same time on the screen...

  • JohannDirryJohannDirry USMember ✭✭

    this is not true. Mobile devices not only allow to have finger input, but mouse and pen input too.

    Ie. I have a pen input on my Samsung Galaxy Note and Mouse Input on my Lumia 950 (via Bluetooth).

    Further, XF can be used to create applications that run on desktop computers to. So I have the need to support those environments.

  • IrrealIrreal RSUniversity ✭✭✭

    I absolutely agree, there is not a single supported Xamarin.Forms platform that doesn't offer some sort of mouse/pen input. bluetooth mice work great with android tablets and phones and especially with UWP devices, Pens work on all 3 platforms. This API is abstract enough to be applicable to all of these input methods and I love the design. I think this should be implemented.

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    I'm not against the idea of tracking some sort of input device. I'm against assuming we get a single one, and it's a mouse.

  • JohannDirryJohannDirry USMember ✭✭
    I agree that the naming is bad, because those methods not only handle mouse input, but all kind of HID's.

    However, using the same name than in WPF/UWP has the advantage that developers do not need to learn a new terminology.
  • rmarinhormarinho PTMember, Insider, Beta Xamurai

    I don't see how this fits with other platforms other then desktop.

  • JohannDirryJohannDirry USMember ✭✭

    it does. in example the iPad Pro (iOS), Surface Book (Windows), the Samsung Galaxy Note (Android) have the capability to be used with a pen or with a mouse.

    There is the option to implement a custom ViewRenderer for this platforms, so the functionality can be provided. It's just tedious to do that every time.

Sign In or Register to comment.