Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Add Wpf Validation Binding #3874

Merged
merged 5 commits into from
Aug 10, 2024
Merged

Conversation

ChrisPulman
Copy link
Member

@ChrisPulman ChrisPulman commented Aug 8, 2024

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

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

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);
    }
}

@ChrisPulman ChrisPulman merged commit 16cd48a into main Aug 10, 2024
1 check passed
@ChrisPulman ChrisPulman deleted the CP_FeatureWpfBindWithValidation branch August 10, 2024 15:23
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants