Skip to content

[BUG] RelayCommand with default parameter not executing #516

@DavidStania

Description

@DavidStania

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Hi all,

I've created a new relaycommand like this here:

        private bool ResetFormCanExecute()
        {
            return !ImageLoading;
        }

        [RelayCommand(CanExecute = nameof(ResetFormCanExecute))]
        private async void ResetForm(bool alert = false)
        {
            if (alert && !(await _messageService.DisplayAlert("Reset", "Alles zurücksetzen?")))
                return;

            ScannedData = string.Empty;
            Comment = string.Empty;

            foreach (var item in Items)
            {
                System.IO.File.Delete(item.FilePath);
            }

            Items.Clear();
        }

XAML:

<Button Text="Formular zurücksetzen" 
                    Command="{Binding ResetFormCommand}" 
                    Margin="0,25,0,0" 
                    Background="{DynamicResource Gray400}"></Button>

The tooltip shows me a binding to IRelayCommand'1 but the other commands have a binding to IRelayCommand.
In my case, the Command will not execute and the canExecute method also not execute.

If I remove the parameter "bool alert = false" the relaycommand works.

Expected Behavior

Accepting a methods for RelayCommands with default parameters.

Steps To Reproduce

Create a RelayCommand with default parameters.

Link to public reproduction project repository

https://github.com/DavidStania/RelayCommandFail.git

Environment

- .NET MAUI CommunityToolkit: CommunityToolkit.Mvvm 8.1.0-preview1
- OS: Microsoft Windows 11 Pro 10.0.22621 Build 22621
- .NET MAUI: 7.0

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    by designSome behavior that is intended and not an issuemvvm-toolkit 🧰Issues/PRs for the MVVM Toolkit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions