avalonia-docs
avalonia-docs copied to clipboard
Add docs for ICustomHitTest
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);
}
Oh that works? Extending the grabber area of a GridSplitter (or other resizing controls) would be another good use case.
Oh, thinking about that before would save a ton of time with GridSplitter indeed
But it works only until there is another hit-testable element overlapping this area, that was earlier in the tree (in reverse order)