-
Notifications
You must be signed in to change notification settings - Fork 28
Css Imports
Import a file, an application resource (in ResourceDictionary) or embedded resource by using the @import "<source>";
statement. You can use this statement in every css file to share variables, mixins or style-declarations.
Write the relative path with forward-slashes or double backward slashes, i.e.
@import "a/relative/path.scss";
or
@import "a\\relative\\path.scss";
Write the key of the resource into the quotes.
@import "applicationResourceKey";
Include the "path" of the embedded resource. If the file embedded-style.scss
was placed in the folder my/resource/path
, then the correct path is
@import "my/resource/path/embedded-style.scss";
or
@import "my\\resource\\path\\embedded-style.scss";
.
Don't forget to set the Build Action of the (s)css-file to "Embedded Resource".
For XamlCSS to be able to localize your embedded resource, check the following:
-
Ensure that the default-namespace and the assembly-name are the same.
I.e if your assembly is named "My.Great.Assembly", then the default-namespace should be exactly the same. -
On Xamarin or UWP provide search assemblies
When you callCss.Initialize(...)
, be sure to provide assemblies containing embedded css-styles. UWP and plattforms Xamarin.Forms runs on don't support enumerating all assemblies so you have to provide them explicitly. I.e.XamlCSS.XamarinForms.Css.Initialize(this, new []{ typeof(TypeInAssemblyContainingEmbeddedCssStyles).Assembly });
Most of the time the assembly containing the embedded (s)css-file is the one containing yourApp.cs
file, so you can write:
XamlCSS.XamarinForms.Css.Initialize(this, new []{ typeof(App).Assembly }); // this is an instance of App
@import "My/Relative/path.scss";
@import "applicationResourceKey";
@import "My/Resource/Path/EmbeddedStyle.scss";