Skip to content
Nuvyntra Labs

Documentation

Forms

FormViewModel in Core, UnoFormViewModel for Uno Platform bindings, dirty confirm, SubmitAsync, undo/redo.

Forms, dirty guard, undo

FormViewModel lives in Core and does not reference Uno Platform. UnoFormViewModel adds INotifyDataErrorInfo. Field(name, value) creates a FormField<T>. Bind(field, propertyName, notifyCanExecute) wires the public property and CanExecute. When IDialogs is registered, leaving a dirty form confirms “Discard changes?”. Tests set DirtyNavigation = DirtyNavigationMode.SilentBlock. SubmitAsync(work) calls MarkClean() on success.

public sealed class ProductEditViewModel : UnoFormViewModel
{
    private readonly FormField<string> _name;

    public ProductEditViewModel()
    {
        _name = Field("Name", "");
        Bind(_name, nameof(Name), () => SaveCommand.NotifyCanExecuteChanged());
    }

    public string Name
    {
        get => _name.Value ?? "";
        set => _name.Value = value;
    }

    private Task<Outcome> SaveAsync(CancellationToken ct) =>
        SubmitAsync(token => _catalog.SaveAsync(Name, token), cancellationToken: ct);
}

Discussion

Comment on Plugin.Uno.MVVMExpress. The thread lives on this component's GitHub repository (nuvyntralabs/Plugin.Uno.MVVMExpress). Sign in with GitHub — Giscus uses Discussions, Utterances uses Issues.