Articles in this section
Category / Section

How to disable Xamarin.Forms button

1 min read

This article explains how to disable the button with command interface usage.


Typically, IsEnabled property is used to determine the interaction of the Xamarin.Forms button.


Consider If the use case is depending on command interface in button, using the IsEnabled property does not make any UI difference as per the MSDN guidelines stated “Do not use the IsEnabled property of Button, if you are using the command interface”.


This article will guide you how to change the enabled state of SfButton with Command interface, based on the toggle value of switch control as shown in the following code snippets.



<Switch HorizontalOptions="Center"  VerticalOptions="Center" IsToggled="{Binding IsButtonEnabled}"  />
            Command="{Binding ButtonCommand}" >


To handle their enabled or disabled state, you need to execute the CanExecute method (CanExecuteClickCommand) of buttons command. For getting this dynamic update, you also need to call ChangeCanExecute of buttons command in IsToggled binding property as shown in the following code snippet.



        public Command ButtonCommand { get; set; }
        public bool IsButtonEnabled
            get { return isButtonEnabled; }
                isButtonEnabled = value;
        bool CanExecuteClickCommand(object arg)
            return isButtonEnabled;
        public ViewModel()
            ButtonCommand = new Command(ExecuteClickCommand, CanExecuteClickCommand);
        void ExecuteClickCommand(object obj)
            //Execute Xamarin.Forms SfButton Command action.


Dynamically handle the IsEnabled property of Xamarin.Forms Button



Download the complete sample here.


See Also:

What are the visual states available in Xamarin.Forms Button?

How to customize the Xamarin.Forms Button?



Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Please sign in to leave a comment