dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22k stars 1.72k forks source link

TappedGestureRecognizer ignores Frame's IsEnabled #21619

Open Mano176 opened 5 months ago

Mano176 commented 5 months ago

Description

When having a TapGestureRecognizer inside a Frame that has IsEnabled set, the TapGestureRecognizer behaves weird depending on the platform.

Steps to Reproduce

MainPage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TestMauiApp.MainPage"
             x:Name="this">

    <StackLayout>

        <Frame IsEnabled="{Binding IsFrameEnabled, Source={x:Reference this}}">

            <Frame.GestureRecognizers>
                <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
            </Frame.GestureRecognizers>

            <Label Text="I am a Label" />
        </Frame>

        <Button Text="IsEnabled-Switcher" 
                Clicked="Button_Clicked" />

    </StackLayout>
</ContentPage>

MainPage.xaml.cs:

using System.ComponentModel;

namespace TestMauiApp;

public partial class MainPage : ContentPage, INotifyPropertyChanged
{
    public MainPage()
    {
        InitializeComponent();
    }

    public new event PropertyChangedEventHandler? PropertyChanged;

    protected virtual void NotifyPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    public bool IsFrameEnabled { get; set; }

    private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
    {
        Console.WriteLine("Here");
    }

    private void Button_Clicked(object sender, EventArgs e)
    {
        IsFrameEnabled = !IsFrameEnabled;
        NotifyPropertyChanged(nameof(IsFrameEnabled));
    }
}

If we initialize the IsFrameEnabled-Property like this public bool IsFrameEnabled { get; set; } = true;, the Frame behaves like expected.

Link to public reproduction project repository

https://github.com/Mano176/MauiTapGestureRecognizerRepo

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

mattleibow commented 5 months ago

Does this work with Border?

Mano176 commented 5 months ago

I added a reproduction project repository.

@mattleibow Sorry, I don't understand what you mean by "Does this work with Border?"

XamlTest commented 5 months ago

Verified on VS 17.10.0 Preview 3.0(8.0.20). Repro on Windows 11, Android 14.0-API34. Work as expected on iOS 17.2 and MacCatalyst. TestMauiApp.zip

sisaacks commented 5 months ago

I have somewhat of a similar issue, I have a frame inside of a contentview. The contentview is displayed on another page. The tap gesture does not work at all. I can put a button outside of the frame, add the command to the button and it works perfectly.

FinnKr commented 5 months ago

Does this work with Border?

I've tested it with <Border ...> instead of <Frame ...> and it seems to be working fine with Border. The visual appearance of Border is different though.

In new .NET MAUI projects Border should be used instead of Frame (still included for easier migration from Xamarin.Forms): https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/frame?view=net-maui-8.0

JavierFajardoSecanda commented 3 months ago

It's not working also with StackLayout