MarkInvalid validation textbox using MVVM

I have a textbox that has a validation on it, in validation, it checks if its isNullOrEmpty. Validation works, but I am having difficulty if the user never selects the text box and clicks, I want the validation to run again. I was able to accomplish this in the XAML.cs file using:

Validation.MarkInvalid(cb.GetBindingExpression(dp), validationError);

      

Now with MVVM I am confused how can I do this from the viewmodel.
Text field in subject:

        <TextBox>
            <TextBox.Text>
                <Binding Path="LastName">
                    <Binding.ValidationRules>
                        <validationRules:IsNullOrEmptyValidationRule/>
                    </Binding.ValidationRules>
                    <Binding.UpdateSourceTrigger>PropertyChanged</Binding.UpdateSourceTrigger>
                    <Binding.Mode>TwoWay</Binding.Mode>
                </Binding>
            </TextBox.Text>
        </TextBox>

      


Any ideas?

+3
c # validation wpf mvvm


source to share


No one has answered this question yet

See similar questions:

49
Checking the syntax of bound controls in WPF

or similar:

3998
How to validate an email address in JavaScript
3175
How do I validate an email address using a regular expression?
2303
Checking decimal numbers in JavaScript - IsNumeric ()
1258
What is the difference between MVC and MVVM?
55
Correct validation with MVVM
3
WPF MVVM Authentication
2
Data validation of text written in TextBox, MVVM C #
0
WPF validation in textbox only on buttonclick not on windowload
0
check if the value in the textbox is valid
0
Validating TextBox in ViewModel



All Articles
Loading...
X
Show
Funny
Dev
Pics