Button not enabling when its CanX property returns true
See original GitHub issueReproduced in this repo here: https://github.com/mariocatch/stylet-foo
I’m using the default Stylet template with dotnet core 3.1. I simply added a property/method for reproducing the issue.
<TextBox Text="{Binding Username,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
Width="100" Height="100"/>
<Button Command="{s:Action Do}">Foo</Button>
public class ShellViewModel : Screen
{
public string Username { get; set; }
public void Do() { }
public bool CanDo => !string.IsNullOrWhiteSpace(Username);
}
Breakpoint on CanDo
property is hit once and never hit again. Changing the value in the TextBox
, while calling set
, does not retrigger the CanDo
property.
I’ve also tried using backing fields with SetAndNotify
, to no avail:
public string Username { get => username; set => SetAndNotify(ref username, value, nameof(Username)); }
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
CanExecute() returns true and button is still disabled
Jerry's answer is most likely correct that the problem is RaiseCanExecuteChanged is not raised automatically in that implementation of ICommand, ...
Read more >Button IsEnabled property in Windows Platform · Issue #7377
Description When I set up the Button's "IsEnabled" property, programmatically. The expected behavior is working in all platforms.
Read more >LWC: Only enable button if options are available
In your code, if showButton is true, then disabled is true -- but if you want to show the button, you don't want...
Read more >Enable/Disable Button in UserControl - Microsoft Q&A
I expected the Button to be enabled/disabled like in a "normal" ContentView/ContentPage, setting the CanExecute-Method in my ViewModel to true ...
Read more >Disable button if user can't use it
The Button only receives true and false to enable and disable it's function, so you need to define the logic which user can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, you’ll need to raise an INPC event for
CanLogin
wheneverUsername
changes. I’ll make sure the wiki makes this clear.I normally wire things together in the constructor:
I’d be happy to handle the wiki change if you’d like