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.

Extend DependsOnAttribute for commands

See original GitHub issue

When using an RelayCommand (e.g. from MvvmLight), where the CanExecute depends on the value of a property, the DependsOnAttribute could be extended, so each time the property changes, the RaiseCanExecuteChanged() method of the command is invoked.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
tom-englertcommented, Dec 21, 2017

Raising a property change event on the command property itself should have the same effect as triggering the CommandManager.InvalidateRequerySuggested() , so that should work already:

public class SurveyViewModel
{
    public bool IsSubmitEnabled { get; set; }

    [DependsOn(nameof(IsSubmitEnabled))]
    public RelayCommand SubmitCommand => new RelayCommand(OnSubmit, CanSubmit);

    public bool CanSubmit()
    {
        return IsSubmitEnabled;
    }
    public void OnSubmit(){
        ...
    }        
}
0reactions
zihotkicommented, Dec 21, 2017

@tom-englert Good point, somehow I didn’t think about it. Tested and verified that it indeed works like a charm.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Similar to DependsOnPropertiesAttribute for Methods ...
Hello, What do I need: Attribute like DependsOnPropertiesAttribute for methods, to list the properties the Can-State of command depends on.
Read more >
Deploying Extensions
<group>: Here you write the name of the group of extensions that you want your extension to belong to (e.g., <group>Example Group</group>), this...
Read more >
What are TestNG Dependent Tests and How to make ...
In this section, we will move our dependency commands over to the XML file. TestNG lets you create dependencies between groups in the...
Read more >
Define the order for deploying resources in ARM templates
Describes how to set one Azure resource as dependent on another resource during deployment. The dependencies ensure resources are deployed ...
Read more >
How to automatically call the CanExecute method when ...
How to automatically call the CanExecute method when properties change with MVVM Light in Windows and Phone apps. When using commands, usually ...
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