How to get/overwrite the styles defined inside the styles.xml (or any other default Xamarin style files) from outside the Xamarin app?

Viewed 78

I have an app that can be styled for different customers. I use the styles.xml to style the app for each customer. However, I need to compile the app, every time I need to change the styles. I want to avoid this by getting these style definition from an outside file configuration, and then apply them at run time. I´m already doing this for other resources like images and texts/labels.

Is this possible? How?

Regards

2 Answers

I'll give an example for a color.

If a style has <Setter Property="BackgroundColor" Value="{StaticResource Color1}" />, then that refers to a Resource with key Color1.

In App.xaml.cs, read the config, use it to construct a Color instance. then set that Resource:

Color color1 = ...;
Application.Current.Resources["Color1"] = color1;
Related