question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Button not enabling when its CanX property returns true

See original GitHub issue

Reproduced 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:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
canton7commented, Jul 28, 2020

Yes, you’ll need to raise an INPC event for CanLogin whenever Username changes. I’ll make sure the wiki makes this clear.

I normally wire things together in the constructor:

Bind(s => s.Username, (o, e) => NotifyOfPropertyChange(nameof(CanLogin)));
1reaction
haven1433commented, Aug 24, 2020

I’d be happy to handle the wiki change if you’d like

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found