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
22.23k stars 1.76k forks source link

BackButtonBehavior not working #19171

Closed acaliaro closed 2 months ago

acaliaro commented 11 months ago

Description

I have a problem with BackButtonBehavior but I can't tell you if it's a problem with MAUI, the MVVM toolkit, or the MAUI toolkit. I have a page that opens in the main page's onAppearing method. A parameter is passed to this page which, in the ApplyQueryAttributes event, sets a property identified as ObservableProperty (IsFirstTime) to true. This property set to true, via the InvertedBoolConverter converter, sets the "IsVisible" of the BackButtonBehavior to false, but the arrow in the navigationbar continues to be seen. If instead of setting the IsFirstProperty to true in the ApplyQueryAttributes method, I set it to true in the SetupViewModel constructor, the arrow disappears correctly.

Steps to Reproduce

run the sample

Link to public reproduction project repository

https://github.com/acaliaro/MauiAppbackbuttonproblem

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11

Did you find any workaround?

no

Relevant log output

No response

XamlTest commented 10 months ago

Verified this on Visual Studio Enterprise 17.9.0 Preview 2(8.0.3). Repro on Android 14.0-API34, Windows 11, iOS 17.0 and MacCatalyst with below Project: MauiAppbackbuttonproblem.zip

image

tentom commented 7 months ago

I think I have a similar problem and it seems to be resolved by setting the binding mode to TwoWay

and I think the reason why this is not working out of the box is because the BackButtonBehaviour bindable property has the default value for the binding mode set to "OneTime". Try setting it to "OneWay"

acaliaro commented 4 months ago

@samhouts any news on this?

kubaflo commented 4 months ago

@acaliaro using Mode=OneWay like this for example IsVisible="{Binding IsBackButtonVisible, Mode=OneWay} accomplishes what you want :)

samhouts commented 2 months ago

Looks like this fix is available in 9.0 preview 7! Thanks!!!