Answer the question
In order to leave comments, you need to log in
Validation with ReactiveUI.Validation?
Goodnight! I'm building a client-server application for myself and ran into a validation issue with ReactiveUI.Validation. Namely, the problem is that if the ViewModel has one property, then the validation works, but after 2 property changes. As soon as I add the 2nd property, everything works fine.
I read the documentation, found 1 example and created a test project.
MainWindowViewModel.cs
public class MainWindowViewModel : ReactiveValidationObject<MainWindowViewModel>
{
[Reactive]
public string FirstName { get; set; } = string.Empty;
public MainWindowViewModel()
{
this.ValidationRule(viewmodel => viewmodel.FirstName,
fs => !fs.Contains(" "),
"Не может быть пробелов");
this.ValidationRule(viewModel => viewModel.FirstName,
firstName => !string.IsNullOrWhiteSpace(firstName),
"Имя не может быть пустым");
}
}
<reactiveui:ReactiveWindow
x:Class="ReactiveValidation.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:vms="clr-namespace:ReactiveValidation.ViewModels"
x:TypeArguments="vms:MainWindowViewModel"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:prism="http://prismlibrary.com/"
xmlns:reactiveui="http://reactiveui.net"
prism:ViewModelLocator.AutoWireViewModel="True"
Title="{Binding Title}" Height="350" Width="525" >
<StackPanel>
<TextBox Text="{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
md:HintAssist.Hint="Имя" Style="{DynamicResource MaterialDesignFloatingHintTextBox}" Margin="30"/>
</StackPanel>
</reactiveui:ReactiveWindow>
public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
{
public MainWindow()
{
InitializeComponent();
ViewModel = new MainWindowViewModel();
this.WhenActivated(disposableRegistration =>
{
});
}
}
public partial class App
{
protected override Window CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
}
}
public class MainWindowViewModel : ReactiveValidationObject<MainWindowViewModel>
{
[Reactive]
public string FirstName { get; set; } = string.Empty;
[Reactive]
public string Test { get; set; }
public MainWindowViewModel()
{
this.ValidationRule(viewmodel => viewmodel.FirstName,
fs => !fs.Contains(" "),
"Не может быть пробелов");
this.ValidationRule(viewModel => viewModel.FirstName,
firstName => !string.IsNullOrWhiteSpace(firstName),
"Имя не может быть пустым");
this.ValidationRule(
vm => vm.Test,
test => !string.IsNullOrWhiteSpace(test),
"567");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question