Code Source
ISource is the source of Acss source code. Currently we provide two types of code sources, local code sources (FileSource) and embedded code sources (EmbeddedSource).
Local Code Source
Local code sources use local files as code input. We support two loading methods, load by file or load by directory.
1. Loading by document
var loader = AcssContext.Default.GetService<IAcssLoader>();
var source1 = new FileSource("Acss/Case.acss");
loader.Load(Application.Current.Styles, source1);
// Use prefer path $"{debugRelative}Acss/Case.acss" if it is valid.
// Or use the path "Acss/Case.acss".
var source2 = new FileSource("Acss/Case.acss", $"{debugRelative}Acss/Case.acss");
loader.Load(Application.Current.Styles, source2);
2. Load from folder
var loader = AcssContext.Default.GetService<IAcssLoader>();
loader.LoadCollection(this, new FileSourceCollection("Acss/"));
loader.LoadCollection(this, new FileSourceCollection("Acss/", "../../Acss/"));
Priority paths are supported whether loading by file or by directory. Priority paths are used first when they are valid. This is useful in a debugging environment.
We can use the directory where the source code is located first, and the directory under the current application as a second choice.
Embedded Code Source
We also support embedding code sources into applications as Avalonia resources; see How to use Acss.Fluent for the usage of the three EmbeddedSource parameters.
The embedded resource approach is much more friendly to the way individual files are packaged.
1. Single Uri loading
var loader = AcssContext.Default.GetService<IAcssLoader>();
loader.Load(
Application.Current.Styles,
new EmbeddedSource(
new Uri("avares://Nlnet.Avalonia.Css.Fluent/Acss/AccentColor.acss"),
PreferLocalPath,
UseRecommendedPreferSource,
AutoExportSourceToLocal));
2. Batch Load by Uri
var loader = AcssContext.Default.GetService<IAcssLoader>();
loader.LoadCollection(
Application.Current.Styles,
new EmbeddedSourceCollection(
new Uri("avares://Nlnet.Avalonia.Css.Fluent/Acss/"),
PreferLocalPath,
UseRecommendedPreferSource,
AutoExportSourceToLocal));
Last updated
Was this helpful?