Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsHitTestVisible does not work when disabled #17972

Open
awp-sirius opened this issue Jan 14, 2025 · 4 comments
Open

IsHitTestVisible does not work when disabled #17972

awp-sirius opened this issue Jan 14, 2025 · 4 comments
Labels
bug by-design The behavior reported in the issue is actually correct.

Comments

@awp-sirius
Copy link

Describe the bug

Hello! My UserControl has Border on background with Tapped EventTriggerBehavior handling.
On top I show ContentControl.

When I set IsEnabled="false" for ContentControl, it becomes "transparent" for input events. as if I set IsHitTestVisible=false...
Forcing IsHitTestVisible="True" or Focusable="True" does not solve the problem.

As far as I understand, IsEnabled makes IsHitTestVisible false and Focusable false, but I would like to be able to control it

To Reproduce

<Grid>
    <Border Background="#55425312">
        <Interaction.Behaviors>
            <EventTriggerBehavior EventName="Tapped">
                <InvokeCommandAction Command="{Binding CloseAll}"/>
            </EventTriggerBehavior>
        </Interaction.Behaviors>
    </Border>
    <ContentControl Content="{Binding Control}"
                    IsEnabled="False"
                    Focusable="True" IsHitTestVisible="True"
                    HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>

Expected behavior

I would like disabled elements to not become "transparent" or the ability to control this.

Avalonia version

11.2.3

OS

Windows

Additional context

My ContentControl can be of different shapes, so I can't add an empty border behind it, above the background :(

@awp-sirius awp-sirius added the bug label Jan 14, 2025
@maxkatz6 maxkatz6 added the by-design The behavior reported in the issue is actually correct. label Jan 15, 2025
@awp-sirius
Copy link
Author

awp-sirius commented Jan 15, 2025

avalonia:
https://github.com/user-attachments/assets/fde29790-df62-4db6-b85f-555af7e070da

    <Grid>
        <Grid.Styles>
            <Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
                <Setter Property="Content" Value="ispointerover"/>
            </Style>
        </Grid.Styles>
        
        <Button Content="button" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
        <Border IsEnabled="False" HorizontalAlignment="Center" VerticalAlignment="Center"
                Height="100" Width="100" Background="Blue"
                IsHitTestVisible="True" Focusable="True"/>
    </Grid>

wpf:
https://github.com/user-attachments/assets/297b5f9a-7268-4f6d-ab06-613e9bba3dfb

<Grid>
    <Button HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
            HorizontalContentAlignment="Left" VerticalContentAlignment="Top">
        <Button.Style>
            <Style TargetType="Button">
                <Setter Property="Content" Value="button"/>
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Content" Value="IsMouseOver"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>
    <Border IsEnabled="False" HorizontalAlignment="Center" VerticalAlignment="Center"
            Height="100" Width="100" Background="Blue"
            IsHitTestVisible="True" Focusable="True"/>
</Grid>

@timunie
Copy link
Contributor

timunie commented Jan 15, 2025

Idea: maybe you can get in PointerEventArgs the controls below your pointer and filter yourself if the event is valid or not

@awp-sirius
Copy link
Author

awp-sirius commented Jan 15, 2025

Idea: maybe you can get in PointerEventArgs the controls below your pointer and filter yourself if the event is valid or not

PointerMoved or PointerPressed?

PointerMoved is called only if there is mouse movement. It doesn't work separately on click.
PointerPressed only works when you right-click or click with the wheel (if use Button).

@awp-sirius
Copy link
Author

I found a workaround if don't use the button in the background:

    private void InputElement_OnPointerPressed(object? sender, PointerPressedEventArgs e)
    {
        var p = e.GetPosition(this);
        var vis = this.GetVisualAt(p);
        if (Equals(sender, vis))
        {
            ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug by-design The behavior reported in the issue is actually correct.
Projects
None yet
Development

No branches or pull requests

3 participants