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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Identify repeated code1m 1s
-
Exercise 1: Examine an app containing repeated code2m 5s
-
Define and use resources3m 33s
-
Exercise 2: Use page-level resources2m 44s
-
Use and update dynamic resources3m 1s
-
Exercise 3: Dynamically update resources3m 14s
-
Create consistent UI with styles7m 34s
-
Exercise 4: Create and apply a style2m 37s
-
Exercise 5: Use style inheritance to refactor repeated code2m 19s
-
Create and utilize application-wide resources3m 41s
-
Exercise 6: Use application-wide resoures2m 7s
-
Apply user accessibility choices with built-in styles2m 56s
-