ICommand interface CanExecute method question

failedtofail

Member
Joined
Jun 16, 2022
Messages
17
Programming Experience
Beginner
My program is based on the MVVM structure. In essence the click of a button kicks of a series of calcs with the answers displayed in textboxes. Button is bound to a property of ICommand type in the ViewModel.

I currently have:

C#:
public bool CanExecute(object parameter)
        {
            return true;
        }

All tutorials I've watched seem to just have the above for the CanExecuteMethod - always returning true. I am looking for an example on how I can modify the return statement of this method to return false once the program has finished executing so that I can activate a list of options for the user such as Redo Calcs, Print Output, Go to Main Menu, etc. once the program has finished.

I have not implemented these yet, but my thoughts are to have these further options being implemented by associated buttons (tied to other ICommands) with these buttons appearing below the outputs once the CanExecute returns false.

Thanks.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,514
Location
Chesapeake, VA
Programming Experience
10+
The most common version of this to not allow the "Save" or "OK" or "Submit" button to be enabled until all the fields have valid values.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
6,514
Location
Chesapeake, VA
Programming Experience
10+

failedtofail

Member
Joined
Jun 16, 2022
Messages
17
Programming Experience
Beginner
This C# Corner article seems good and will take me some time to work through. I've never come across Bindable Objects, CommandManager.RequerySuggested, BooleanToVisibilityConverter or Prims before. Managed to install the Prism add-ons successfully but there was still and error.

Had to change

class MainWindowViewModel : BindableBase

to

class MainWindowViewModel : BindableBase, ICommand

and implement the ICommand interface.

Now to learn all those other terms.

Thanks for the link.
 
Top Bottom