How to call a command from outside its class in VS Community Toolkit #520
-
I have a command named Login: [Command(PackageIds.Login)] Inside this ExecuteAsync some logic is performed so that if a singleton class contains or not information about the login, the button shows "Login" or "Logout" and the procedure is of course, different. I already have a hint, since inside the BaseCommand interface there is a method called InitializeAsync that says: Initializes the command. This method must be called from the method for the command to work. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
When you call RegisterCommandsAsync() at the package level, this method uses reflection to find all subclasses of BaseCommand and create and initialize the commands by calling InitializeAsync(). You can add any code that you want in this method, including code to store a reference to the singleton. Later in BeforeQueryStatus() and Execute() you are free to do whatever you want. |
Beta Was this translation helpful? Give feedback.
When you call RegisterCommandsAsync() at the package level, this method uses reflection to find all subclasses of BaseCommand and create and initialize the commands by calling InitializeAsync(). You can add any code that you want in this method, including code to store a reference to the singleton. Later in BeforeQueryStatus() and Execute() you are free to do whatever you want.