-
Notifications
You must be signed in to change notification settings - Fork 276
Open
Labels
Description
Possible use case and a demo is extending hit test area:
public class BiggerButton : Button, ICustomHitTest
{
public BiggerButton()
{
ClipToBounds = false; // By default, Avalonia optimizes hit testing by clipping to bounds.
}
protected override Type StyleKeyOverride => typeof(Button); // unrelated to hit test, we just want to reuse Button styles
bool ICustomHitTest.HitTest(Point point) => Bounds
.WithX(0).WithY(0) // reset position relative to the parent, as ICustomHitTest expects the point to be in the local coordinate system
.Inflate(100) // inflate by how much we want hit test to be extended
.Contains(point);
}