With Forge.Forms you can create dynamic forms in WPF from classes or XML. Using this library is straightforward. DynamicForm is a control that will render controls bound to an associated model. A model can be an object, a type, a primitive, or a custom IFormDefinition.
Given the flexibility it provides especially in MVVM based applications, Sachith Liyanagama, is currently porting the project into the * Avalonia framework*.
To get started, check out the original guide for now. Avalonia-Specific guide will be documented later. or follow the installation instructions below.
Cross Platform User Interface (Demo Project)
Desktop | WASM |
---|---|
Type | Sub Types | Screenshot |
---|---|---|
String | String, Password, Multiline | |
Numerical | ||
Date | ||
Time | ||
Selection | ||
Boolean |
Due to the original WPF-Based library ships with dependencies to UI toolkits such as Material Design, there can be certain bottlenecks. Please consider this project/repository to be experimental until a better and cleaner approach has been developed.
Due to the complex usage of deferred bindings in the original project, porting to avalonia is done incermentally. Similarly based on the functionality the components are classified as follows.
First iteration of the controls are ported using basic Fluent Theme styling and later need to be ported to CONTROL THEMES.
Control Type | Status | Comment |
---|---|---|
Action Element | π Ported | |
Boolean Field | π Ported | |
Break Element | π Ported | |
Card Element | π Ported | Dependency to Card Component of Material Design, need to work on sizing. |
Converted Field | π Ported | Need to test more |
Date Field | π Ported | Must use DateTimeOffset for the bound properties instead of DateTime |
Time Field | π Ported | Avalonia Returns DateTime offset. Need to change the Resource type |
Divider Element | π Ported | |
Error Text Element | π€ Will be removed | Do not needed. |
Heading Element | π Ported | |
Image Element | π Ported | Need to copy image to the "Assets" folder and write path in the format of: [Image("avares://(AssemblyName)/Assets/(filename)")] |
Selection Field | π Ported | Dynamic Binding not available due to Binding Incompatibilities |
Slider Field | π Ported | |
Text Element | π Ported | WASM seems to not handle the MultiBinding Strings. |
Title Element | π Ported | |
Toggle Field | π Ported |
Logic | Status | Comment |
---|---|---|
Form Builder | π Ported | Need more testing |
XML Form Builder | π Ported | Need more testing. Bindings seems not to work. |
Attributes | π Ported | Mostly working, other than dynamic property bindings for Selection. |
Form Binding Extension | π Recreated | Given that the DataContext setting is not set mostly during initialization, had to optimize logic and seperate certain Bindings to use a converter (FormBindingConverter). |
Freezable Proxy Objects | π Ported | Replaced Ifreezable with avalonia object and pass binding from control. |
Dialogs | π Ported | Need more testing and style optimization. Window needs to be optimized. |
File Binding | π€ Incomplete | FileWatcher only works on Desktop. Need to find an alternative. |
Data Validation | π Recreated | Rewrote the validation logic in a simple manner using a model wrapper, Validation event and DataValidationErrors |
Framework | Method | Status | How to Use |
---|---|---|---|
Avalonia - Fluent | Styles & Control Theme | Currently being optimized | xaml <StyleInclude Source="avares://Forge.Forms.AvaloniaUI/Themes/Fluent.axaml" /> |
Material | Styles & Control Theme | Currently being optimized | xaml <StyleInclude Source="avares://Forge.Forms.AvaloniaUI/Themes/Material.axaml" /> |
Import Project Forge.Forms.AvaloniaUI
For default style sheet, add this to App.axaml
<StyleInclude Source="avares://Forge.Forms.AvaloniaUI/Themes/Base.axaml" />
If you want to use DynamicForm
, import this namespace in XAML:
<xmlns:forms="clr-namespace:Forge.Forms.AvaloniaUI.Controls;assembly=Forge.Forms"/>
And use the control:
<forms:DynamicForm Model="{Binding Model}" />
If you only need to show windows and dialogs, use the Show
helper:
using Forge.Forms;
await Show.Window().For(new Alert("Hello world!"));
using Forge.Forms;
await Show.Dialog().For<Login>();
Note: if you are using Show.Dialog()
without specifying a dialog identifier, it expects you to have a DialogHost
in your XAML tree.