This is a small demo app to show how to use the VisualStateManager in Xamarin.Forms to control the look of controls depending on the value of their IsEnabled property. This is just the tip of the VisualStateManager iceberg, but it's a great place to start.
It was not too long ago when I thought I had almost no control at all over how various view elements would look in Xamarin.Forms when their IsEnabled property would get set to false. The stages of discovery went a little something like this:
- Holy guacamole... I have no control whatsoever over how a button looks when it is disabled!
- I'm so, so, so, sad... In order to control the look when disabled, I'm going to have to write a custom renderer.
- Well, at least I have some limited control over the disabled look using styles and a data trigger based on the value of IsEnabled. Still a pretty icky UI.
- Rejoice!! The VisualStateManager gives me complete control over the look when disabled without delving into the bowels of each platform using a custom renderer!
Furthermore, I am a huge fan of the the Prism MVVM framework in conjunction with Xamarin.Forms, and I believe the more sample code available the better! This demo app will show you how to customize the look of a styled button when it is disabled, in a very simple Xamarin.Forms app using the Prism MVVM framework.
Quick Note: You might notice the switch control is slightly customized, since I strongly dislike the default pink color used on the Android switch by default:
- There is an implicit style set for the switch OnColor in App.xaml.cs (in the cross-platform project).
- The value for "colorAccent" in the Android project's styles.xml file has been changed to be not pink.
- You can view the actual code changes in this commit.
There are Debug.WriteLine calls throughout the sample code to illustrate app flow, show you when the buttons are responding to taps, etc.