Services
Icon provider
In order to use the Icon and IconButton elements, the application must register an IIconProvider service.
Bulletcode.UI makes it possible to use an icon font as the source of icons, to ensure that they look the same on all platforms.
The font must be registered just like any other custom font:
builder.ConfigureFonts( fonts => {
fonts.AddFont( "lucide.ttf", "lucide" );
} );
When registering the icon provider service, the name of the JSON mapping file and the name of the font must be specified:
services.AddIconProvider( "lucide.json", "lucide" );
Both the icon font and the JSON mapping file can be generated using the bc-build-icons tool which is provided by the bc-font-utils NPM package. The Icons chapter contains more information about generating icon fonts. In order to use the font in a Bulletcode.UI application, the following options should be specified in the YML file:
outputTTF: true
outputWOFF2: false
outputCSS: false
outputJSON: true
This ensures that the generated font has the TTF format and that the JSON mapping file is generated.
Both the font and the mapping file should also be added to the .csproj file:
<ItemGroup>
<MauiFont Include="Resources\Fonts\*.ttf" />
<MauiAsset Include="Resources\Fonts\*.json" LogicalName="%(Filename)%(Extension)" />
</ItemGroup>
File dialog
The IFileDialog service makes it possible to display the standard open file and save file system dialogs. It is only available on Windows.
To register this service, call the RegisterUIServices() extension method of the IServiceCollection:
services.RegisterUIServices();
The IFileDialog service has the following methods:
GetOpenFileName()— displays the open file dialogGetSaveFileName()— displays the save file dialog
Both methods return the path of the selected file or null if the dialog was cancelled.
The following options can be specified:
Title— the title of the dialog.Filters— a dictionary containing one or more filters for the dialog. The keys are the display names, and the corresponding values specify the filter patterns (for example,"*.txt;*.doc").DefaultExtension— the default extension appended to the file name when using the save dialog.