0

In Xamarin forms we have delegate commands like this:

        /// Gets or sets the logout command.
        /// </summary>
        /// <value>
        /// The logout command.
        /// </value>
        public DelegateCommand LogoutCommand { get; set; }

Which is initialized in the constructor like this:

this.LogoutCommand = new DelegateCommand(this.ExecuteLogoutCommand);

Currently, the ExecuteLogoutCommand is return void type, but I wish to make it Task as it has an async task. But doing so breaks the initialization in the constructor. Any help here?

Update The following link helped me: https://johnthiriet.com/mvvm-going-async-with-async-command/

But now I get this error in my Unit Tests:

MobileApp.Core.UnitTests.Add.ConfirmationPageViewModelUnitTests.OnNavigatedToBackBehavior threw exception: System.MissingMethodException: Method not found: 'MobileApp.Core.IServices.IAsyncDelegateCommand MobileApp.Core.ViewModel.Add.ConfirmationPageViewModel.get_GoBackHomeCommand()'
7
  • Does this answer your question? How to use async method in DelegateCommand Commented Jul 8, 2020 at 11:51
  • @mihailduchev No, I tried this. couldn't get it to work. Commented Jul 8, 2020 at 11:56
  • What exactly have you tried? Commented Jul 8, 2020 at 11:58
  • @mihailduchev I wish to override the delegate command method to have an option of returning task method. Is that possible? Commented Jul 8, 2020 at 12:42
  • johnthiriet.com/mvvm-going-async-with-async-command This article help me a lot Commented Jul 8, 2020 at 14:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.