Skip to content

In Code

XAML (preferred)

<ContentPage x:Class="...">
    <StyleSheet Source="appresources/style.css" />

the Source argument takes an Uri relative to the current xaml control, or relative to the application root if it starts with a /. The style.css has to be an EmbeddedResource.

alternatively, you can inline your style in a CDATA Section

<ContentPage x:Class="...">
^contentpage {
    background-color: orange;
    padding: 20;

stacklayout > * {
    margin: 3;

do not abuse that second syntax.

in C

From an embedded resource:

myPage.Resources.Add(StyleSheet.FromAssemblyResource(this.GetType().Assembly, ""));

or from a TextReader:

using (var reader = new StringReader(my_css_string))

StyleSheet, XamlC and other potential optimizations

At this time, CSS StyleSheets are parsed and evaluated at runtime. That aren't compiled. Every time a StyleSheet is used, it's reparsed again. If parsing time is an issue, enabling caching is trivial, but comes at memory cost.