We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

IsEnabled Not working on Sf Button

Hi

I have a page that has 2 buttons i wish to disable unless my app is registered, and have set it up through binding.

the first button on the form (Clock) takes no notice of the fact that IsEnabled = False, however the 2nd (Job) button next to it disables/enables as it should and works fine.

if i manually set IsEnabled To False rather than through binding then it doesnt work either, it totally disregards it just the same as the binding
if i use IsVisible instead, then that works fine (but i dont want to do that in my app)

if i set the containing grid's IsEnabled, then it disables my button but of course doesnt 'grey out' the buttons which i want it to do - i just want IsEnabled to do what it says on the tin.

heres my code snippet

         <Grid>
            <Grid.RowDefinitions>
               <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
               <ColumnDefinition Width="5*" />
               <ColumnDefinition Width="5*" />
            </Grid.ColumnDefinitions>

            <sfbuttons:SfButton Text="Clock"
               Grid.Column="0" 
               Style="{StaticResource SfButtonStyle2}"
               ImageSource="{PluginLibrary:PlatformImage SourceImage='Clock32W.png'}"
               HorizontalOptions="StartAndExpand"
               CommandParameter="C"
               Command="{Binding SaveClockingCommand}"
               IsEnabled="{Binding IsAppRegistered}">
            </sfbuttons:SfButton>

            <sfbuttons:SfButton Text="Job"
               Grid.Column="1"
               Style="{StaticResource SfButtonStyle2}"
               ImageSource="{PluginLibrary:PlatformImage SourceImage='Hammer32W.png'}"
               HorizontalOptions="EndAndExpand"
               Clicked="JobLogButton_Clicked"
               IsEnabled="{Binding IsAppRegistered}" >
            </sfbuttons:SfButton>
         </Grid>

ive done some googling and research and through the link here:

https://forums.xamarin.com/discussion/47857/setting-buttons-isenabled-to-false-does-not-disable-button

it seems to indicate that if you remove the Command it works fine (and hey presto it does work) and i think this may have been cured in native xamarin forms, as before i migrated to using Sf buttons didnt have this issue and didnt need to try find some convoluted 'workaround' to cure what should be functional in the first place. maybe i used 'clicked' instead of a command, and thats why it worked then, im not sure it was a while ago, but a command is much neater in my MVVM code behind and i would like to keep it that way

so whats the score with this please - is there a cure & can you fix it

btw heres the command i use in my ViewModel, it's argument specifies the type of clocking transaction i save, i.e C,J,A

      public ICommand SaveClockingCommand { get; private set; }
      SaveClockingCommand = new Command<string>(async (x) => await SaveClocking(x));


thanks

Bob


5 Replies

RA Rachel A Syncfusion Team August 1, 2019 08:39 AM UTC

Hi Bob, 
 
We have validated your requirement and we would like to let you know that, we have handled the IsEnabled property of SfButton based on the return value of CanExecute provided from Command property as per the Xamarin.forms architecture. Hence, the binding value of IsEnabled is not set while using Command, due to the binding breaks.  
 
Please refer the below screen shot.  
 
 
If your requirement is about to enable or disable the SfButton based on the local Boolean variable with also using the Command means, it has been done through by return value of CanExecute. If we return the CanExecute as false, it makes SfButton as disable, otherwise, it will be enabling the SfButton and invoke the Execute event of Command. We have prepared the sample based on your requirement. Please download it from the below link. 
 
        public bool IsButtonEnabled 
        { 
            get 
            { 
                return isButtonEnabled; 
            } 
            set 
            { 
               isButtonEnabled = value; 
                WorkflowCommand.ChangeCanExecute(); 
                OnPropertyChanged("IsButtonEnabled"); 
            } 
        } 
. . . 
WorkflowCommand = new Command<SfPopupLayout>(ExecuteClickCommand, CanExecuteClickCommand); 
. . . 
 
        void ExecuteClickCommand(SfPopupLayout popupLayout) 
        { 
            //do something.  
            popupLayout.Show(); 
        } 
 
        bool CanExecuteClickCommand(object arg) 
        { 
            return IsButtonEnabled; 
        } 
 
 
Regards, 
Rachel. 



BN Bob Needham August 1, 2019 09:47 AM UTC

Hi Rachel

Many thanks for that, i have a better understanding now of what's going on and why it's done this way, even if it just seems a little too much 'out there' for what i personally want to do in this case lol, when a simple binding depending on an external setting would do, but it has added to my knowledge and will help me adhere to the proper MVVM coding way i suppose

on the other issue, can you at least tell me where we are upto with the SfComboBox crashing on UWP please, including the sf sample app - have you acknowledged this and is someone at least looking at it as i have no info

thanks

Bob



MK Muneesh Kumar G Syncfusion Team August 2, 2019 08:45 AM UTC

Hi Bob, 
 
We have attached the SfComboBox to the sample provided in earlier update. Unfortunately, we could not reproduce the crash. Please have the sample with which we have checked the issue.  
 
 
Please check with the sample and if the issue mentioned occurs in different scenario. Please modify the sample with the issue reproducing sample which will be helpful for us to analyze further and provide an appropriate solution. 
 
Thanks,    
Muneesh Kumar G.   
 



BN Bob Needham August 2, 2019 10:29 AM UTC

Hi Maneesh

your code does indeed *now* work, but you are using v17.2.0.39 nugets of sf controls

when i loaded up the SampleBrowser.SfComboBox project from v17.2.0.34 it just crashed on opening as reported. i have just upgraded that to 39 and it now works so something has changed, but the main thing is now its working i suppose

i cant upgrade my project to 39 because another fix for the missing text in the input boxes wont be ready until 6th august in the official release as reported by rachel before so i will give all my probs a good testing after then. i tested it in 39 and its still wrong

did you replicate the issue i reported back yesterday when you change to use xamarin forms latest? you reported that as non replicateable but it was easy to do so. please advise on your findings

thanks

Bob



MK Muneesh Kumar G Syncfusion Team August 2, 2019 10:55 AM UTC

Hi Bob, 
 
Thanks for your update.  
 
In August 6th weekly nuget you will get the both fixes, please test that nuget and let us know if you have any other queries.  
 
Also, currently we are checking the issue reported in 146291 forum, we will update the status in that forum link itself, please check it.  
 
Thanks,    
Muneesh Kumar G.   
 


Loader.
Live Chat Icon For mobile
Up arrow icon