Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That's normal behaviour.</p> <p>The binding expression specified in your DependencyProperty (i.e. Text in this case) will do an initial bind when the element is initialized/loaded (and Update the Target from the Source...i.e. the Text property of your TextBox is set to the value in the property in your Source with the specified Path (n.b. ignore the case where a Path isn't specified for now)).</p> <p><code>UpdateSourceTrigger="Explicit"</code> just stops the automatic update of the value in the Target (i.e. the Text property of your TextBox) from being sent to your Source (e.g. a ViewModel/model) .... (don't confuse this option with controlling the Update of the Target).</p> <p>During the initial bind I'd imagine that the binding engine sees that the "source" has an IDataErrorInfo and so it checks if the "item" is valid...and if not...you get the standard error adorner surrounding your TextBox (defined by an ErrorTemplate) ....so that it matches the state of the data in your model....that's all logical.</p> <p>To stop the error indicators being shown too aggressively after the initial loading of your view...you could try this workaround.</p> <p>You could change your IDataErrorInfo so that you are in control of when it will perform the validation checking logic.</p> <p>Have a flag that gets set after the view has been loaded...which allows the IDataErrorInfo validation code to be run...and not before.</p> <p>Once loaded from that point on, calls to UpdateSource will fire the Validator which will catch invalid data (because your Loaded flag will be true, and your validation logic will do it's magic).</p> <p>You could use something like this:</p> <pre><code>public class CustomerViewModel : IDataErrorInfo { public bool DoValidation { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Error { get { if (DoValidation) { if (error on any properties) return "error on these ....."; } return null; // no errors } } public string this[string columnName] { get { if (!DoValidation) { return null; } string result = null; if (columnName == "FirstName") { if (string.IsNullOrEmpty(FirstName)) result = "Please enter a First Name"; } if (columnName == "LastName") { if (string.IsNullOrEmpty(LastName)) result = "Please enter a Last Name"; } return result; } } } </code></pre> <p>Set the DoValidation property on the model after the Loaded event has occurred.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload