Skip to content

Add docs for ICustomHitTest #676

@maxkatz6

Description

@maxkatz6

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);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions