/// <summary>
        /// Implements the equality check against the PropertyName and Control.
        /// </summary>
        /// <param name="obj">The ValidationSummaryItem being compared.</param>
        /// <returns>A value indicating whether the two references are equal in value.</returns>
        public override bool Equals(object obj)
        {
            ValidationSummaryItemSource other = obj as ValidationSummaryItemSource;

            if (other == null)
            {
                return(false);
            }
            return(this.PropertyName == other.PropertyName && this.Control == other.Control);
        }
Exemplo n.º 2
0
        private void ExecuteClick(object sender)
        {
            ListBox lb = sender as ListBox;

            if (lb != null)
            {
                ValidationSummaryItem vsi = lb.SelectedItem as ValidationSummaryItem;
                if (vsi != null && this.FocusControlsOnClick)
                {
                    int idx;
                    // Ensure the currently selected item source is valid
                    if (vsi.Sources.Count == 0)
                    {
                        // Clear the current ESI source if the ESI has none, such as when the ESI has changed
                        this._currentValidationSummaryItemSource = null;
                    }
                    else
                    {
                        // If the current ESI source is not part of the current set, select the first one by default.
                        idx = FindMatchingErrorSource(vsi.Sources, this._currentValidationSummaryItemSource);
                        if (idx < 0)
                        {
                            this._currentValidationSummaryItemSource = vsi.Sources[0];
                        }
                    }

                    // Raise the event
                    FocusingInvalidControlEventArgs e = new FocusingInvalidControlEventArgs(vsi, this._currentValidationSummaryItemSource);
                    this.OnFocusingInvalidControl(e);

#if OPENSILVER
                    // Raise the AutomationPeer event
                    ValidationSummaryAutomationPeer peer = ValidationSummaryAutomationPeer.FromElement(this) as ValidationSummaryAutomationPeer;
                    if (peer != null && AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked))
                    {
                        peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked);
                    }
#endif

                    // Focus the target, which will usually be the current ESI source or the overwritten one
                    if (!e.Handled && e.Target != null && e.Target.Control != null)
                    {
                        e.Target.Control.Focus();
                    }

                    // Update currently selected item, but only if there are multiple ESI sources.
                    if (vsi.Sources.Count > 0)
                    {
                        idx = FindMatchingErrorSource(vsi.Sources, e.Target);
                        idx = idx < 0 ? 0 : ++idx % vsi.Sources.Count;
                        this._currentValidationSummaryItemSource = vsi.Sources[idx];
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void FocusCycling()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                page.nameTextBox.Text = "ABCDEFG!@#$";
                Assert.AreEqual(1, vs.Errors.Count);

                ValidationSummaryItem newVsi = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, null, null);

                ValidationSummaryItemSource source1 = new ValidationSummaryItemSource("prop1", page.nameTextBox);
                newVsi.Sources.Add(source1);
                ValidationSummaryItemSource source2 = new ValidationSummaryItemSource("prop2", page.emailTextBox);
                newVsi.Sources.Add(source2);

                vs.Errors.Add(newVsi);
                ValidationSummaryItem newVsi2 = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, null, null);
                vs.Errors.Add(newVsi2);

                // Setup the delegate to capture the event
                vs.ErrorsListBoxInternal.SelectedItem      = newVsi;
                ValidationSummaryItemSource selectedSource = null;
                vs.FocusingInvalidControl += new EventHandler <FocusingInvalidControlEventArgs>(delegate(object o, FocusingInvalidControlEventArgs e)
                {
                    selectedSource = e.Target;
                });

                // First click
                vs.ExecuteClickInternal();
                Assert.AreEqual(source1, selectedSource);

                // Second
                vs.ExecuteClickInternal();
                Assert.AreEqual(source2, selectedSource);

                // Cycle back
                vs.ExecuteClickInternal();
                Assert.AreEqual(source1, selectedSource);

                // Change the ESI
                vs.ErrorsListBoxInternal.SelectedItem = newVsi2;

                // First click with new ESI
                vs.ExecuteClickInternal();
                Assert.AreEqual(null, selectedSource);
            });

            EnqueueTestComplete();
        }
Exemplo n.º 4
0
        public void SelectionChanged()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                page.nameTextBox.Text = "ABCDEFG!@#$";
                Assert.AreEqual(1, vs.Errors.Count);

                ValidationSummaryItem newEsi = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, null, null);

                ValidationSummaryItemSource source1 = new ValidationSummaryItemSource("prop1", page.nameTextBox);
                newEsi.Sources.Add(source1);
                ValidationSummaryItemSource source2 = new ValidationSummaryItemSource("prop2", page.emailTextBox);
                newEsi.Sources.Add(source2);

                vs.Errors.Add(newEsi);
                ValidationSummaryItem newEsi2 = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, null, null);
                vs.Errors.Add(newEsi2);

                // Setup the delegate to capture the event
                bool selectionChanged = false;
                vs.SelectionChanged  += new EventHandler <SelectionChangedEventArgs>(delegate(object o, SelectionChangedEventArgs e)
                {
                    selectionChanged = true;
                });

                vs.ErrorsListBoxInternal.SelectedItem = newEsi;
                vs.ErrorsListBoxInternal.SelectedItem = newEsi2;
                // First click
                vs.ExecuteClickInternal();
                Assert.IsTrue(selectionChanged);
            });

            EnqueueTestComplete();
        }
Exemplo n.º 5
0
 //
 // Summary:
 //     Initializes a new instance of the System.Windows.Controls.FocusingInvalidControlEventArgs
 //     class.
 //
 // Parameters:
 //   item:
 //     The error that is selected in the System.Windows.Controls.ValidationSummary list.
 //
 //   target:
 //     The control/property pair that will receive focus.
 public FocusingInvalidControlEventArgs(ValidationSummaryItem item, ValidationSummaryItemSource target)
 {
 }
Exemplo n.º 6
0
        public override bool Equals(object obj)
        {
            ValidationSummaryItemSource source = obj as ValidationSummaryItemSource;

            return((source != null) ? ((this.PropertyName == source.PropertyName) && ReferenceEquals(this.Control, source.Control)) : false);
        }
Exemplo n.º 7
0
 //
 // Summary:
 //     Initializes a new instance of the System.Windows.Controls.ValidationSummaryItem
 //     class with the specified error message, header, item type, source, and context.
 //
 // Parameters:
 //   message:
 //     The text of the error message.
 //
 //   messageHeader:
 //     The header of the item, such as the property name.
 //
 //   itemType:
 //     Specifies whether the error originated from an object or a property.
 //
 //   source:
 //     The source of the error message, including the originating control or property
 //     name.
 //
 //   context:
 //     The context in which the error occurred.
 public ValidationSummaryItem(string message, string messageHeader, ValidationSummaryItemType itemType, ValidationSummaryItemSource source, object context)
 {
 }
 /// <summary>
 /// Initializes a new instance of the ValidationSummaryItemEventArgs class.
 /// </summary>
 /// <param name="item">The selected ValidationSummaryItem</param>
 /// <param name="target">The target is the ValidationSummaryItemSource that will be focused.</param>
 public FocusingInvalidControlEventArgs(ValidationSummaryItem item, ValidationSummaryItemSource target)
 {
     this.Handled = false;
     this.Item    = item;
     this.Target  = target;
 }
 /// <summary>
 /// Initializes a new instance of the ValidationSummaryItemEventArgs class.
 /// </summary>
 /// <param name="item">The selected ValidationSummaryItem</param>
 /// <param name="target">The target is the ValidationSummaryItemSource that will be focused.</param>
 public FocusingInvalidControlEventArgs(ValidationSummaryItem item, ValidationSummaryItemSource target)
 {
     this.Handled = false;
     this.Item = item;
     this.Target = target;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the ValidationSummaryItem class.
 /// </summary>
 /// <param name="message">The error message.</param>
 /// <param name="messageHeader">The header/prefix of the item, such as the property name.</param>
 /// <param name="itemType">The type of error, such as Property or Entity level.</param>
 /// <param name="source">The source of the error message, including the originating control and/or property name.</param>
 /// <param name="context">Context from which the error occurred.  This general property can be used as a container to keep track of the entity, for instance.</param>
 public ValidationSummaryItem(string message, string messageHeader, ValidationSummaryItemType itemType, ValidationSummaryItemSource source, object context)
 {
     this.MessageHeader = messageHeader;
     this.Message       = message;
     this.ItemType      = itemType;
     this.Context       = context;
     this.Sources       = new ObservableCollection <ValidationSummaryItemSource>();
     if (source != null)
     {
         this.Sources.Add(source);
     }
 }
Exemplo n.º 11
0
 private static int FindMatchingErrorSource(IList <ValidationSummaryItemSource> sources, ValidationSummaryItemSource sourceToFind)
 {
     if (sources != null)
     {
         for (int i = 0; i < sources.Count; i++)
         {
             if (sources[i].Equals(sourceToFind))
             {
                 return(i);
             }
         }
     }
     return(-1);
 }