dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

MAUI Button IsEnabled Binding

Open pouchbunny opened this issue 3 years ago • 7 comments

Describe the bug

I started noticing my buttons acting weirdly when trying to disable via bindings where in my current project even after setting IsEnabled binding value to false I can still click the button and fire off the binding command.

I created a new app to test and found out that despite when the app first starts and the binding is false, the button can still be clicked until I set it true, then back to false. Only then will it start acting as it should.

IMAGES:

  1. When started - original button is enabled despite CanClick is false
  2. Button clicked and breakpoint fires
  3. Continued and yellow box shows CanClick is still false
  4. Clicked Enable Counter twice (first time to set CanClick to true, then to false) Clicked button not disabled

Regression

No response

Reproducible in sample app?

  • [ ] This bug can be reproduced in the sample app.

Steps to reproduce

1. New Maui App
2. Add CommunityToolKit
3. Add viewmodel and BindingContext and DataTypes to xaml and xaml.cs
4. Add bindings (can set the bool CanClick binding false in [ObservableProperty] or in constructor but no effect as CanClick is still false when starting app)
5. Add [RelayCommands] to both buttons and set break point on original's RelayCommand
6. Add new button to CanClick = !CanClick (to turn the original button on and off)
7. Run app
8. Click original button and breakpoint will fire

Expected behavior

The original button should be disable from the start as the binding CanClick is initially set to false

Screenshots

image image image image

Windows Build Number

  • [ ] Windows 10 1809 (Build 17763)
  • [ ] Windows 10 1903 (Build 18362)
  • [ ] Windows 10 1909 (Build 18363)
  • [ ] Windows 10 2004 (Build 19041)
  • [ ] Windows 10 20H2 (Build 19042)
  • [ ] Windows 10 21H1 (Build 19043)
  • [ ] Windows 11 21H2 (Build 22000)
  • [X] Other (specify)

Other Windows Build number

Version 10.0.19044 Build 19044

App minimum and target SDK version

  • [ ] Windows 10, version 1809 (Build 17763)
  • [ ] Windows 10, version 1903 (Build 18362)
  • [ ] Windows 10, version 1909 (Build 18363)
  • [ ] Windows 10, version 2004 (Build 19041)
  • [ ] Other (specify)

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

17.3.0 Preview 3.0

Device form factor

Desktop

Nuget packages

image

Additional context

No response

Help us help you

No.

pouchbunny avatar Aug 09 '22 16:08 pouchbunny

Hello pouchbunny, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Aug 09 '22 16:08 ghost

As a follow up. In my own app I created a button to change the value of the binding of one of my buttons that's not being disabled from the start as it should. With the new button it acts just like what I described above. I can officially enable and disable my save button by changing the binding value with the new RelayCommand attached to the new button.

pouchbunny avatar Aug 09 '22 17:08 pouchbunny

Yes, it's a big issue, I am struggling for over 1 week thinking my code has the problem. then I read this here which is the same as my issue. I have 2 buttons both of them are getting value by the binding first one is always true whatever I do except I set the value to the same binding value of the second button. image

really I begin to believe that CommunityToolkit and DotNet Maui are very buggy and it needs a long time to be stable, which pushes us to move to other languages, really sorry to say that.

Ahmadmansoor avatar Aug 14 '22 20:08 Ahmadmansoor

"really I begin to believe that CommunityToolkit and DotNet Maui are very buggy and it needs a long time to be stable"

You haven't demonstrated that this is in fact a bug in the MVVM Toolkit whatsoever yet. As far as I can see, it's not.

It might be a bug in MAUI, yes, and for that this is the wrong repo. Have you opened an issue on the MAUI repo too? Also can you provide a minimal repro? We can't just take 10 screenshots of code to investigate.

Sergio0694 avatar Aug 14 '22 20:08 Sergio0694

@Sergio0694 I think u have your point, but really it is disappoint us when we face simple issues that should not exist or miss essential features. On the other hand, sharing our code for some private software is not easy as well too, I hope u understand the situation. anyway a big thanks to the contributor for their great work, and I am sorry if I show a misunderstanding.

Ahmadmansoor avatar Aug 15 '22 14:08 Ahmadmansoor

to be more silicification, my problem is the button can't disable itself from the C# code. and sometimes from the other buttons as well.

Ahmadmansoor avatar Aug 15 '22 16:08 Ahmadmansoor

It seems as as long the command method with the [RelayCommand] is synchronous, all works fine. When using an Async command, the button stays gray after the first click (although it's clickable as expected). Only on Windows, not in Android.

mvervoort avatar Aug 22 '22 18:08 mvervoort

Closing this, as it just seems like an issue with MAUI (also I think I've seen this being mentioned in a separate issue as well though I don't have it handy right now). I'd recommend opening an issue in the MAUI repo (or finding one if it already exists) and possibly linking this one there for reference 🙂

Sergio0694 avatar Dec 18 '22 01:12 Sergio0694

move to maui

heartacker avatar Dec 18 '22 02:12 heartacker