/// <summary> /// Adds async scalar validator. /// </summary> /// <param name="input">The scalar input.</param> /// <param name="validator">Delegate to perform validation.</param> /// <param name="displayName">The display name used for fault error message.</param> /// <returns>This template builder for fluent coding.</returns> public T AddAsyncValidator <TElement>(ScalarInput <TElement> input, Func <Task <string> > validator, string displayName) where TElement : UIElement, new() { if (input == null) { throw new ArgumentNullException(nameof(input)); } return(AddAsyncValidator(input.Target, validator, displayName)); }
/// <summary> /// Begins input implementation. /// </summary> /// <param name="flushingTrigger">The flushing trigger.</param> /// <param name="progressiveFlushingTrigger">The progressive flushing trigger.</param> /// <returns>The scalar input.</returns> public ScalarInput <T> BeginInput(Trigger <T> flushingTrigger, Trigger <T> progressiveFlushingTrigger = null) { VerifyNotSealed(); if (Input != null) { throw new InvalidOperationException(DiagnosticMessages.TwoWayBinding_InputAlreadyExists); } return(Input = new ScalarInput <T>(this, flushingTrigger, progressiveFlushingTrigger)); }
void IScalarValidation.OnFlushed <T>(ScalarInput <T> scalarInput, bool makeProgress, bool valueChanged) { if (!makeProgress && !valueChanged) { return; } if (valueChanged) { UpdateAsyncErrors(scalarInput.Target); if (Mode != ValidationMode.Explicit) { Validate(false); } } if (UpdateProgress(scalarInput, valueChanged, makeProgress)) { OnProgress(scalarInput); } InvalidateView(); }
internal bool UpdateProgress <T>(ScalarInput <T> scalarInput, bool valueChanged, bool makeProgress) where T : UIElement, new() { Debug.Assert(valueChanged || makeProgress); if (Mode != ValidationMode.Progressive || _showAll) { return(valueChanged); } var scalars = scalarInput.Target; if (scalars == null || scalars.Count == 0) { return(false); } if (makeProgress) { if (_progress.IsSupersetOf(scalars)) { return(valueChanged); } if (valueChanged || _valueChanged.IsSupersetOf(scalars)) { _progress = _progress.Union(scalars); return(true); } } else { _valueChanged = _valueChanged.Union(scalars); } return(false); }
private void OnProgress <T>(ScalarInput <T> scalarInput) where T : UIElement, new() { if (Mode == ValidationMode.Explicit) { return; } if (HasError(scalarInput.Target)) { return; } var asyncValidators = Template.ScalarAsyncValidators; for (int i = 0; i < asyncValidators.Count; i++) { var asyncValidator = asyncValidators[i]; if (asyncValidator.SourceScalars.Intersect(scalarInput.Target).Count > 0) { asyncValidator.Run(); } } }
/// <summary> /// Binds scalar input validation errors to <see cref="ValidationErrorsControl"/>. /// </summary> /// <typeparam name="T">The element type of scalar input.</typeparam> /// <param name="source">The source scalar input.</param> /// <returns>The scalar binding object.</returns> public static ScalarBinding <ValidationErrorsControl> BindToValidationErrorsControl <T>(this ScalarInput <T> source) where T : UIElement, new() { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(new ScalarBinding <ValidationErrorsControl>( onRefresh: (v, p) => { var errors = source.GetValidationInfo(p.FlowIndex).Errors; if (ShouldUpdateItemsSource(v, errors)) { v.ItemsSource = errors; } }, onSetup: null, onCleanup: null)); }
private static ScalarBinding <InPlaceEditor> MergeIntoInPlaceEditor <TEditing, TInert>(this ScalarInput <TEditing> scalarInput, ScalarBinding <TInert> inertScalarBinding) where TEditing : UIElement, new() where TInert : UIElement, new() { Debug.Assert(scalarInput != null); Debug.Assert(inertScalarBinding != null); return(InPlaceEditor.AddToInPlaceEditor(scalarInput, inertScalarBinding)); }