CommunityToolkit icon indicating copy to clipboard operation
CommunityToolkit copied to clipboard

CanExecute is always false on RelayCommand with enum parameter

Open c0debeef opened this issue 10 months ago • 1 comments

public enum MainMenuOption
{
	None = 0,
	Notifications = 1,
	Accounts = 2,
	Settings = 3,
	Exit = 4,
}

public IRelayCommand ChooseMainMenuCommand { get; init; }
private void ChooseMainMenuCommandImplementation(MainMenuOption option) {...}

ChooseMainMenuCommand = new RelayCommand<MainMenuOption>(ChooseMainMenuCommandImplementation);

This button is always disabled:

xmlns:enums="clr-namespace:Project.Enums"

<Button x:Name="xButton"
    Command="{Binding ChooseMainMenuCommand}">
    <Button.CommandParameter>
        <enums:MainMenuOption>Notifications</enums:MainMenuOption>
    </Button.CommandParameter>
</Button>

It runs well if I make the parameter optional: MainMenuOption?

c0debeef avatar Aug 17 '23 10:08 c0debeef

It doesn't work for decimal either, and possibly for other struct types.

c0debeef avatar Aug 29 '23 14:08 c0debeef