From the course: Resources and Styles in Xamarin.Forms

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Exercise 5: Use style inheritance to refactor repeated code

Exercise 5: Use style inheritance to refactor repeated code - Xamarin Tutorial

From the course: Resources and Styles in Xamarin.Forms

Exercise 5: Use style inheritance to refactor repeated code

- [Instructor] So we're back in our tip calculator once again. And the last time we looked at this, we were creating a Style. But the one thing I want to talk about with this is that sometimes Styles themselves can duplicate code because when you're building an application, you're trying to create an overall look. So, it's probably common that in different button styles there will be something in common, maybe a similar color, maybe a similar size, and whatnot. So you can actually build Styles that derive from other Styles to stop duplication. So what we're going to do is we're actually going to take this Style and kind of just split it up between two different Styles. Just to show you how this works. So I'm going to copy this. Let's create another Style. So the first Style is going to be called the baseLabelStyle, and the second one can stay as info. In the base, we're just going to keep the font size. And then in the infoLabelStyle, this will be based off of the other one, so this…

Contents