Willy
Willy

Reputation: 10638

WPF TextBox: prevent validation rule to fire until user edition

In order to control user input on a WPF TextBox I have bound a validation rule to it. Validation rule works perfectly. It validates if TextBox is empty among other things.

But there is a thing I don't like: when window (xaml view) is open for first time, the TextBox marked as invalid (red border around) since this TextBox is empty by default at the beginning.

This TextBox is automatically populated later when user performs some actions on an WPF Listbox in the same window.

So I would like the empty TextBox not being marked as invalid with red border around for first time when window is loaded.

I don't know if there is a way to stop validation rule from being fired for first time and enable it later. If so how?

How can I achieve this?

Upvotes: 0

Views: 469

Answers (1)

mm8
mm8

Reputation: 169160

I don't know if there is a way to stop validation rule from being fired for first time and enable it later. If so how?

Set the ValidatesOnTargetUpdated property of the ValidationRule to false, or don't set it all since false is the default value.

Upvotes: 2

Related Questions