I am using a command binding for a button in Maui. The button's IsEnabled property does not work because of the command binding. Even if IsEnable is set to true, the command is not fired. How can I disable the button in the ViewModel class at the constructor in new Command(..) so that the command does not fire and the button looks disabled? (Like toggling from one to the other button.)
On learn.microsoft.. I read:
Warning
Do not use the IsEnabled property of Button if you're using the command interface.
XAML:
<ScrollView Style="{StaticResource mainScrollView}"> <VerticalStackLayout> <HorizontalStackLayout> <Button Text="Month" Command="{Binding SetMonatCommand}" Style="{StaticResource buttonCalendar}" IsEnabled="{Binding IsListActive}"/> <!-- IsEnabled IS NOT WORKING --> <Button Text="List" Command="{Binding SetListeCommand}" Style="{StaticResource buttonCalendar}" IsEnabled="{Binding IsMonthActive}"/> <!-- IsEnabled IS NOT WORKING --> </HorizontalStackLayout> ... ViewModel:
public partial class CalendarPageViewModel : ObservableObject, INotifyPropertyChanged { private readonly CalendarService _calendarService; [ObservableProperty] private bool _isMonthActive; [ObservableProperty] private bool _IsListActive; public ICommand SetMonthCommand { get; set; } public ICommand SetListCommand { get; set; } public CalendarPageViewModel(CalendarService calendarService) { _calendarService = calendarService; SetMonthCommand = new Command(() => { IsMonthActive = true; IsListActive = !IsMonthActive; }); // is not called when using IsEnabled at the XAML SetListCommand = new Command(() => { IsListActive = true; IsMonthActive = !IsListActive; }); // is not called when using IsEnabled at the XAML } ....