- Home
- Forum
- Xamarin.Forms
- IsEnabled Background Color MVVM
IsEnabled Background Color MVVM
Good day,
Kindly advise how to correctly set the BackgroundColor of a SfButton control when using the control in a MVVM pattern eg
<button:SfButton
Text="Ok" Command="{Binding OkBC}"
IsEnabled="{Binding OkEnable}"
BackgroundColor="Blue" />
Text="Ok" Command="{Binding OkBC}"
IsEnabled="{Binding OkEnable}"
BackgroundColor="Blue" />
The Button when OkEnable = True is enabled and shows correct background color = Blue.
The Button when OkEnable=False is not enabled but shows incorrect background color = White.
Warm regards
Ian
SIGN IN To post a reply.
3 Replies
HM
Hemalatha Marikumar
Syncfusion Team
November 13, 2019 08:57 AM UTC
Hi Ian,
Greetings from Syncfusion.
We have analyzed your query and we would like to let you know that using Disabled VisualState, you can customize the appearance of SfButton. Here we have achieved your requirement by changing the background color of disabled SfButton as per in below code snippet
Code snippet[XAML]:
|
<button:SfButton x:Name="button" Text="Ok" Command="{Binding OkBC}" IsEnabled="{Binding OkEnable}" BackgroundColor="Blue">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Red" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Blue" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</button:SfButton>
|
Please get back to us if you have any further questions on this.
Regards,
Hemalatha M.
IA
Ian
November 13, 2019 11:06 AM UTC
Good day,
I use the PRISM delegate commands as part of the MVVM implementation and found initially that the IsEnabled property was not reacting to changes to the bounded property. Adding CanExecute and RaiseCanExecuteChanged() to the mix remedied the situation.
In summary my question has been resolved using the following:
VisualStateManager
CanExecute in conjunction with DelegateCommand
Adding RaiseCanExcuteChanged to the set property of the ISEnabled binding.
Thank you for the support!
Warm regards
Ian
HM
Hemalatha Marikumar
Syncfusion Team
November 14, 2019 09:35 AM UTC
Hi Ian,
Thanks for your update.
We glad to hear that your requirement has been achieved.
Please let us know if you need any other assistance.
Regards,
Hemalatha M.
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
IA Ian
- Nov 12, 2019 01:34 PM UTC
- Nov 14, 2019 09:35 AM UTC