Xamarin Forms Tips Part 3: Change Randomly A View’s Color At Run-time

Hi everyone, here is the third part of the Xamarin Forms Tips series. Today, we will look at how to change a view’s color randomly at run time. I implemented this feature in the “My Expenditures” application. As you can see on the screenshots above, the first letter of the user’s name changes color every time he runs the app. And it does so randomly. This post is all about implementing this functionality.

The app’s name is : My Expenditures. It is available on Play store and Microsoft store. It provides you a smart way to manage you expenses and income. And very detailed stats about how you spend or make money. You can download and use it. You will also find in the app all the features I talk about here.

Change Randomly A View’s Color At Run-time

We will change the color of the text of a label at run-time. This feature is implemented using markup extensions. We predefined a set of colors which we randomly assign to the view. This is extremely simple and here is the code for it.