AvaloniaSettingsFactory 1.2.6
See the version list below for details.
dotnet add package AvaloniaSettingsFactory --version 1.2.6
NuGet\Install-Package AvaloniaSettingsFactory -Version 1.2.6
<PackageReference Include="AvaloniaSettingsFactory" Version="1.2.6" />
paket add AvaloniaSettingsFactory --version 1.2.6
#r "nuget: AvaloniaSettingsFactory, 1.2.6"
// Install AvaloniaSettingsFactory as a Cake Addin #addin nuget:?package=AvaloniaSettingsFactory&version=1.2.6 // Install AvaloniaSettingsFactory as a Cake Tool #tool nuget:?package=AvaloniaSettingsFactory&version=1.2.6
Avalonia SettingsFactory
Avalonia SettingsFactory is a dynamic UI library that lets you seamlessly implement a settings editor in your Avalonia application using an existing settings object.
Usage
Avalonia SettingsFactory works by reading a decorated settings object and sending the results into a custom view that inherits the SettingsFactory
UserControl included in this library.
The SettingsFactory component can be initialized with the InitializeSettingsFactory
function and an optional SettingsFactoryOptions
instance to configure the front-end actions used by the internal library.
public partial class SettingsView : SettingsFactory, ISettingsValidator
// ...
InitializeComponent();
// ...
SettingsFactoryOptions options = new() {
// Application implementation of a message prompt
AlertAction = (msg) => Debug.WriteLine(msg),
// Folder browse dialog or custom input system.
BrowseAction = async (title) => {
OpenFolderDialog dialog = new() { Title = title };
var result = await dialog.ShowAsync(App.StaticView);
return result;
},
};
// Custom resource loader (must always return a Dictionary<string, string>)
FetchResource = (res) => JsonSerializer.Deserialize<Dictionary<string, string>>(File.ReadAllText(res))
// Implement custom logic to occur after saving or cancelling
AfterSaveEvent += () => {
// Dispose view after saving
(App.StaticView.DataContext as AppViewModel).Content = null;
};
AfterCancelEvent += () => {
// Dispose view after cancelling
(App.StaticView.DataContext as AppViewModel).Content = null;
};
// Initialize the settings layout
InitializeSettingsFactory(
new SettingsFactoryViewModel(canCancel: true), // Build-in or custom ViewModel inheriting SettingsFactoryViewModel
this, // implemented ISettingsValidator
Settings.Config, // Your decorated settings object
options
);
The attached view must also have some assosiated XAML to tell the SettingsFactory where to place the setting elements.
<StackPanel Name="Root">
| This will hold navigation buttons and folders.<Button Name="Save">
| This button will trigger theSave
event.<Button Name="Cancel">
| This button will trigger theCancel
event.<ContentControl Content="{Binding ActiveElement}">
| This will hold the active settings page.
For a basic fluent design page, check out the demo application — SettingsView.axaml
<br>
Each setting (property) can also be validated with custom logic using the ISettingsValidator interface and SettingsFactory indexing.
// Custom validation for specified settings
// in your base settings object
public bool? ValidateString(string key, string value)
{
return key switch
{
// Execute a custom check.
"UserName" => value.All(c => (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')),
// You can also reference other properties using the SettingsFactory indexing.
"FullName" => value.Contains((string)this["FirstName"]!) && value.Contains((string)this["LastName"]!),
// Run a custom action (e.g. change the application theme)
"Theme" => ValidateTheme(value),
// Or return null (default, blank color)
_ => null
};
}
// Validate bool properties
public bool? ValidateBool(string key, bool value) { /* ... */ }
// Check all the properties before saving
// and warn the user about specific settings
public string? ValidateSave(Dictionary<string, bool?> validated)
{
// Singled-out property logic
if (validated["UserName"] == null) {
return "Please enter a username before saving!";
}
// Optionally do one final check on all properties and return a generic error.
// If all property values validated true, return null to continue saving.
return validated.Where(x => x.Value == false).Any() ? "One or more settings could not be verified. Please review your settings." : null;
}
<br>
* Note: Setting properties without a Setting attribute will not be read!
* Check out the Demo application for a complete implementation.
Install
Install with NuGet or build from source.
NuGet
Install-Package AvaloniaSettingsFactory
Install-Package AvaloniaSettingsFactory.Core
Build from Source
git clone https://github.com/ArchLeaders/Avalonia.SettingsFactory.git
dotnet build Avalonia.SettingsFactory
© 2022 Arch Leaders
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Avalonia (>= 11.0.0-preview4)
- Avalonia.Diagnostics (>= 11.0.0-preview4)
- Avalonia.ReactiveUI (>= 11.0.0-preview4)
- AvaloniaSettingsFactory.Core (>= 1.2.6)
- XamlNameReferenceGenerator (>= 1.5.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
11.0.0-rc1.1 | 105 | 6/4/2023 |
11.0.0-preview6 | 316 | 5/3/2023 |
11.0.0-preview5 | 180 | 2/12/2023 |
1.2.6 | 500 | 12/25/2022 |
1.2.5 | 360 | 12/25/2022 |
1.2.4 | 357 | 12/23/2022 |
1.2.3 | 438 | 10/30/2022 |
1.2.2 | 466 | 10/11/2022 |
1.2.1 | 451 | 10/11/2022 |
1.2.0 | 443 | 10/11/2022 |
1.1.14 | 450 | 10/11/2022 |
1.1.13 | 475 | 10/11/2022 |
1.1.12 | 454 | 10/11/2022 |
1.0.1 | 461 | 10/11/2022 |
1.0.0 | 458 | 10/11/2022 |
0.1.11 | 477 | 10/11/2022 |
0.1.10 | 475 | 10/11/2022 |