I'm working on a Xamarin.Forms mobile app. In the UWP version, when I hover over a button, a ~2px gray border appears:
The problem is: when not hovering, the border goes away, leaving that amount of space now empty (or perhaps the border becomes transparent), causing the button to look slightly out of alignment with elements above it.
How do I get rid of that border altogether (when hovering and not hovering)?
I'm using a custom renderer (ButtonExt : Button
), and in the default styles in the PCL, I'm setting the BorderWidthProperty to new Thickness(0)
by default, as well as in the disabled and focused state, like this (leaving out other style properties for clarity):
public static Style ButtonStyle => new Style(typeof(ButtonExt))
{
Setters =
{
new Setter {Property = ButtonExt.BorderWidthProperty, Value = new Thickness(0)}
},
Triggers =
{
// Disabled button
new Trigger(typeof(ButtonExt))
{
Property = VisualElement.IsEnabledProperty,
Value = false,
Setters =
{
new Setter {Property = ButtonExt.BorderWidthProperty, Value = new Thickness(0)}
}
},
new Trigger(typeof(ButtonExt))
{
Property = VisualElement.IsFocusedProperty,
Value = true,
Setters =
{
new Setter {Property = ButtonExt.BorderWidthProperty, Value = new Thickness(0)}
}
}
}
};
But that has no effect. The only thing that works is if I explicitly set the native control border thickness to 0 - Control.BorderThickness = new Thickness(0);
. But that's a little hacky. Ideally there's a way I can remove that border through styles.