Skip to content

BindValidation throws System.NotSupportedException #378

@NaolShow

Description

@NaolShow

Describe the bug

When calling this.BindValidation on a ReactiveUserControl, it throws the exception:
System.NotSupportedException : 'Index expressions are only supported with constants.'

Steps To Reproduce

Follow: https://www.reactiveui.net/docs/handbook/user-input-validation/
And at the end, the bindValidation will throw an error.

Expected behavior

It should not throw an error and just bind correctly

Code

ConnectView:

public partial class ConnectView : ReactiveUserControl<ConnectViewModel> {

        public ConnectView() {
            InitializeComponent();

            // Input validation
            this.WhenActivated(disposables => {

                this.BindValidation(ViewModel, viewModel => viewModel.Username, view => view.FindControl<TextBlock>("UsernameError").Text).DisposeWith(disposables);

            });

        }

        private void InitializeComponent() {
            AvaloniaXamlLoader.Load(this);
        }

    }

ConnectViewModel:

public class ConnectViewModel : ReactiveObject, IValidatableViewModel {

        public ValidationContext ValidationContext { get; } = new ValidationContext();

        [Reactive] public string Username { get; set; } = "";
        [Reactive] public string Password { get; set; } = "";

        public ConnectViewModel() {

            // Username cannot be empty
            this.ValidationRule(viewModel => viewModel.Username, username => !string.IsNullOrEmpty(username), "Username cannot be empty..");

        }

    }

And of course I have a TextBlock with the x:Name attribute with a value of "UsernameError".

Additional context
I am using Avalonia.
Thanks for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions