FAQ Database Discussion Community


FluentValidation not working for a null property

c#,wpf,fluentvalidation,idataerrorinfo
I'm using FluentValidation with IDataErrorInfo, and I have a validator defined as follows: public class StsInfoValidator : AbstractValidator<StsInfo> { public StsInfoValidator() { RuleFor(x => x.SomeProperty).Cascade(CascadeMode.StopOnFirstFailure) .NotNull().NotEmpty().WithMessage("SomeProperty is required."); } } However, passing in a null property doesn't seem to trigger the validator: #region IDataErrorInfo public string this[string columnName] { get...

How to use Exception Messages for IDataErrorInfo on WPF

c#,wpf,mvvm,idataerrorinfo
i was wondering how to best validate some user inputs on the WPF mvvm pattern? I've implemented IDataErrorInfo in my ViewModel. But I don't know how to use this interface with raising an exception. My purpose is to not have any logic in my viewModel. So the validation has to...

Validate a field only if it is populated

c#,wpf,idataerrorinfo
I am having a problem with validating phone numbers. In our system we have two phone numbers which you can store. The problem I am having is that these are optional fields. So I want it to validate the phone number IF and only IF the user has tried to...

Different ControlTemplates for ErrorTemplate

c#,wpf,binding,controltemplate,idataerrorinfo
In my application I have a ControlTemplate which I use to show that the input of a TextBox is invalid. The ControlTemplate is defined as: <ControlTemplate x:Key="TextBoxErrorTemplate" TargetType="Control"> <Grid ClipToBounds="False"> <Border BorderBrush="Red" BorderThickness="1" Margin="-1"> <AdornedElementPlaceholder Name="adornedElement" /> </Border> <Image HorizontalAlignment="Right" VerticalAlignment="Top" Width="16" Height="16" Margin="0,-9,-8,0"...

Combobox and IDataErrorInfo

wpf,vb.net,mvvm,combobox,idataerrorinfo
This is my problem. When I select an item from the combobox, (combobox is populated) I have always red outline. Why ? <ComboBox x:Name="Cmb_USER" TabIndex="5" ItemsSource="{Binding User_USER, ValidatesOnExceptions=True, ValidatesOnDataErrors=True,NotifyOnValidationError=True}" IsEditable="True" DisplayMemberPath ="DescUser" Text="{Binding Path=USER}" Margin="114,105,98,179"/> Public Property User_USER As ObservableCollection(Of Model_User) Private p_USER As String Public Property USER() As String...