Skip to content

This sample aims to provide a clear and concise example of how to implement the disabling functionality for SfButton within Xamarin.Forms application.

Notifications You must be signed in to change notification settings

SyncfusionExamples/How-to-disable-Xamarin.Forms-SfButton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to Disable/Enable SfButton with ICommand usage

This example demonstrates how to to find a way to disable / enable the SfButton when using ICommand. As per the MSDNsuggestion.

Do not use the IsEnabled property of Button, if you are using the command interface.

Please refer KB links for more details,

How to disable the Xamarin Button[SfButton]

Let us have a demo sample with Switch control, and we have changed the enable option of Button based on its IsToggled of Switch.

[XAML]


..  

<Switch HorizontalOptions="Center"  VerticalOptions="Center" IsToggled="{Binding IsButtonEnabled}"  />
<buttons:SfButton 
           ..
           Text="Button" 
           FontSize="18" 
           Command="{Binding ButtonCommand}" >
</buttons:SfButton>

..

Invoke the CanExecute method of button's command while changing the model property of IsButtonEnabled (IsToggled's model property) and, based on the return value of CanExecuteClickCommand, we can enable or disable the Button.

[C#]


       …

       public Command ButtonCommand { get; set; }

       public bool IsButtonEnabled
       {
           get { return isButtonEnabled; }
           set
           {
               isButtonEnabled = value;
               ButtonCommand.ChangeCanExecute();
               OnPropertyChanged();
           }
       }

       bool CanExecuteClickCommand(object arg)
       {
           return isButtonEnabled;
       }

       public ViewModel()
       {
           ButtonCommand = new Command(ExecuteClickCommand, CanExecuteClickCommand);
       }
       
      
       void ExecuteClickCommand(object obj)
       {
           //Execute Xamarin.Forms SfButton Command action.
       }

See Also :

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

How to customize the Xamarin.Forms Button?

Also refer our feature tour page to know more features available in our button.

Troubleshooting

Path too long exception

If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.

About

This sample aims to provide a clear and concise example of how to implement the disabling functionality for SfButton within Xamarin.Forms application.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages