Example #1
0
 private bool IsValidated()
 => !string.IsNullOrWhiteSpace(nameTextBox.Text) &&
 !string.IsNullOrWhiteSpace(phoneTextBox.Text) &&
 !Validator.GetHasError(nameTextBox) &&
 !Validator.GetHasError(phoneTextBox) &&
 hourCB.SelectedItem != null &&
 minuteCB.SelectedItem != null &&
 dateSelector.SelectedDate != null;
Example #2
0
 // Token: 0x060044B8 RID: 17592 RVA: 0x00138162 File Offset: 0x00136362
 internal void ChangeValidationVisualState(bool useTransitions)
 {
     if (!Validation.GetHasError(this))
     {
         VisualStateManager.GoToState(this, "Valid", useTransitions);
         return;
     }
     if (base.IsKeyboardFocused)
     {
         VisualStateManager.GoToState(this, "InvalidFocused", useTransitions);
         return;
     }
     VisualStateManager.GoToState(this, "InvalidUnfocused", useTransitions);
 }
Example #3
0
 /// <summary>
 ///     Common code for putting a control in the validation state.  Controls that use the should register
 ///     for change notification of Validation.HasError.
 /// </summary>
 /// <param name="useTransitions"></param>
 internal void ChangeValidationVisualState(bool useTransitions)
 {
     if (Validation.GetHasError(this))
     {
         if (IsKeyboardFocused)
         {
             VisualStateManager.GoToState(this, VisualStates.StateInvalidFocused, useTransitions);
         }
         else
         {
             VisualStateManager.GoToState(this, VisualStates.StateInvalidUnfocused, useTransitions);
         }
     }
     else
     {
         VisualStateManager.GoToState(this, VisualStates.StateValid, useTransitions);
     }
 }
Example #4
0
 /// <summary>
 /// Parse the target error state and update the IsValid property
 /// </summary>
 private void ParseTargetValidState()
 {
     if (!String.IsNullOrEmpty(this.PropertyPath))
     {
         // If PropertyPath is set, the IsValid state is not used and defaults to true, even if the PropertyPath is itself invalid.
         this.IsValid = true;
     }
     else if (this.Target != null)
     {
         this.IsValid = !Validation.GetHasError(this.Target);
     }
     else
     {
         // If no target is specified, IsValid state defaults back to true.
         this.IsValid = true;
     }
     this.UpdateValidationState();
 }
        /// <summary>
        /// Returns whether or not a DependencyObject has errors.
        /// </summary>
        /// <param name="element">The element to test.</param>
        /// <returns>Whether or not it has errors.</returns>
        public static bool ElementHasErrors(DependencyObject element)
        {
            if (element == null)
            {
                return(false);
            }

            if (Validation.GetHasError(element))
            {
                return(true);
            }
            else
            {
                int childrenCount = VisualTreeHelper.GetChildrenCount(element);

                for (int i = 0; i < childrenCount; i++)
                {
                    DependencyObject childElement = VisualTreeHelper.GetChild(element, i);

                    DataForm childDataForm = childElement as DataForm;

                    // If we've found a child DataForm, validate it instead of continuing.
                    if (childDataForm != null)
                    {
                        childDataForm.ValidateItem();

                        if (!childDataForm.IsItemValid)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (ElementHasErrors(childElement))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
        }
        public static bool IsValid(this DependencyObject node, bool isFocusErrorControl = false)
        {
            if (node == null)
            {
                return(true);
            }

            bool hasError = Validation.GetHasError(node);

            if (hasError)
            {
                if (isFocusErrorControl)
                {
                    node.IfType <IInputElement, IInputElement>(Keyboard.Focus);
                }

                return(false);
            }

            return(LogicalTreeHelper.GetChildren(node).OfType <DependencyObject>().All(subnode => IsValid(subnode, isFocusErrorControl)));
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool IsValid()
        {
            bool result = true;

            foreach (KeyValuePair <string, List <ValidationRule> > kvp in this.rules)
            {
                foreach (ValidationRule rule in kvp.Value)
                {
                    System.Windows.Controls.ValidationResult vresult = rule.Validate(this.properties[kvp.Key].GetValue(this.CurrentItem, null), System.Globalization.CultureInfo.CurrentUICulture);
                    if (vresult.IsValid == false)
                    {
                        result = false;
                        if (!Validation.GetHasError(this.controls[kvp.Key]))
                        {
                            Validation.MarkInvalid(this.bindings[kvp.Key], new ValidationError(rule, this.bindings[kvp.Key].ParentBindingBase, vresult.ErrorContent, null));
                        }
                    }
                }
            }

            return(result);
        }