It should be possible to style VisualElement
with triggers for hover and handle hover events.
Analog to System.Windows.UIElement
, the class VisualElement
should get an IsMouseOver
dependency property, an MouseEnter
and an MouseLeave
event.
IsMouseOver
property should get set to True
after MouseEnter
fired.IsMouseOver
property should get set to False
after MouseLeave
fired.analog to the MouseEventArgs
, the argument of the events should provide
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.
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}" /> <Style.Triggers> <Trigger TargetType="Button" Property="IsMouseOver" Value="True"> <Setter Property="TextColor" Value="White" /> </Trigger> </Style.Triggers> </Style>
The events may ie. be used for presenting a custom cursor when hovering, like when previewing the brush in an painting application.
Posts
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...
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.
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.
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.
However, using the same name than in WPF/UWP has the advantage that developers do not need to learn a new terminology.
I don't see how this fits with other platforms other then desktop.
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.