Join Helen Miller for an in-depth discussion in this video Identify repeated code, part of Resources and Styles in Xamarin.Forms.
- [Instructor] In this demonstration we're going to have a look at a simple XAML page, and try and identify some areas where we have repeated hard-coded values on that page. Let's go and have a look at the StandardTipPage.xaml file. What we're looking for is repeated XAML and hard-coded values. Some good examples are the background color on the grid, which is hard-coded to Silver. Also, we can see on each of the labels we're repeating values. For example, text color, which has been set to Navy for each of these labels.
Also, our FontSize is repeatedly hard-coded. And, even our FontAttribute of Bold. These are all classic examples of repeated XAML values and hard-coded values. These will make your XAML really hard to maintain over time. For example, if you wanted to change your label color you'd have to identify each of the locations, and hope you find them all, and then change them manually, which is not ideal. In this demonstration we saw how XAML pages can often contain repeated or hard-coded values.
This course was created by Xamarin University. We are honored to host this training in our library.