reactiveui / ReactiveUI

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms that is inspired by functional reactive programming. ReactiveUI allows you to abstract mutable state away from your user interfaces, express the idea around a feature in one readable place and improve the testability of your application.
https://www.reactiveui.net
MIT License
8.12k stars 1.12k forks source link

Feature Add Wpf Validation Binding #3874

Closed ChrisPulman closed 3 months ago

ChrisPulman commented 3 months ago

What kind of change does this PR introduce?

feature

What is the current behavior?

No code bindings exist supporting Validation

What is the new behavior?

Added Wpf Bind which uses ReactiveUI ReactiveProperty with validation as a validation source

What might this PR break?

New Feature

Please check if the PR fulfills these requirements

Other information: Example

public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
{
    public MainWindow()
    {
        InitializeComponent();
        ViewModel = new MainWindowViewModel();
        this.WhenActivated(cleanup =>
        {
                this.BindWithValidation(
                ViewModel,
                vm => vm.NoSymbolsTextProperty.Value,
                view => view.NoSymbolsEntry.Text,
                .DisposeWith(cleanup);
        });
    }
}

using System.ComponentModel.DataAnnotations;
using ReactiveUI;

public class MainWindowViewModel : ReactiveObject
{
    [RegularExpression(@"^[^!@#$%^&*()]*$", ErrorMessage = "Symbols not allowed!")]
    public ReactiveProperty<string> NoSymbolsTextProperty { get; }

    public MainWindowViewModel()
    {
        NoSymbolsTextProperty = new ReactiveProperty<string>().AddValidation(() => NoSymbolsTextProperty);
    }
}
github-actions[bot] commented 3 months ago

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.