Xamarin.Forms And Resources

ResourcesOften, there will be multiple views in your form that share the same values (e.g., font size, color, etc.).  There are a couple ways you can handle this:

  • Create a resource dictionary and then refer to the resources using the key and the keyword StaticResource
  • Declare constants and then refer to them using x:Static

While the names are very similar, x:Static and Static resources work differently.  The former access a public static constant  (or a public static property defined by a class).  The latter, static resources, is a markup extension supported by xAML that depends on the creation of a resource dictionary.

Let’s look at how you might use both.  More…

About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET will be released early in 2025. Liberty is a Senior SW Engineer for CNH and he was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Microsoft MVP.
This entry was posted in Essentials. Bookmark the permalink.