當前位置: 首頁>>代碼示例>>C#>>正文


C# TextBox.ClearValidationError方法代碼示例

本文整理匯總了C#中System.Windows.Controls.TextBox.ClearValidationError方法的典型用法代碼示例。如果您正苦於以下問題:C# TextBox.ClearValidationError方法的具體用法?C# TextBox.ClearValidationError怎麽用?C# TextBox.ClearValidationError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Windows.Controls.TextBox的用法示例。


在下文中一共展示了TextBox.ClearValidationError方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Reminder

        public void Reminder()
        {
            var textBox = new TextBox();
            var inputTypes = new InputTypeCollection { typeof(TextBox), typeof(Selector) };
            textBox.SetForInputTypes(inputTypes);
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            var errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            Assert.Fail("Implement");
            // CollectionAssert.IsEmpty(errorNode.Errors);

            textBox.SetValidationError();
            Assert.AreEqual(true, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            // CollectionAssert.AreEqual(new[] {TestValidationError.GetFor(textBox)} ,errorNode.Errors);

            textBox.ClearValidationError();
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            // CollectionAssert.IsEmpty(errorNode.Errors);
        }
開發者ID:gitter-badger,項目名稱:Gu.Wpf.ValidationScope,代碼行數:26,代碼來源:ScopeTests.TextBox.cs

示例2: NodesForInputTypesTextBox

            public void NodesForInputTypesTextBox()
            {
                var textBox = new System.Windows.Controls.TextBox();
                var stackPanel = new StackPanel();
                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection { typeof(System.Windows.Controls.TextBox), typeof(Selector) };
                Scope.SetForInputTypes(stackPanel, inputTypes);

                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(stackPanel));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(textBox));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));
                var errorNode = (InputNode)Scope.GetNode(textBox);
                Assert.AreEqual(false, errorNode.HasError);
                Assert.AreNotSame(ErrorCollection.EmptyValidationErrors, errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Children);

                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                textBox.SetValidationError(validationError);

                Assert.AreEqual(true, Scope.GetHasError(stackPanel));
                Assert.AreEqual(true, Scope.GetHasError(textBox));
                var expectedErrors = new[] { validationError };
                CollectionAssert.AreEqual(expectedErrors, Scope.GetErrors(stackPanel));
                CollectionAssert.AreEqual(expectedErrors, Scope.GetErrors(textBox));

                var scopeNode = (ScopeNode)Scope.GetNode(stackPanel);
                CollectionAssert.AreEqual(new[] { errorNode }, scopeNode.Children);
                Assert.AreSame(errorNode, Scope.GetNode(textBox));
                Assert.AreEqual(true, scopeNode.HasError);
                Assert.AreEqual(true, errorNode.HasError);
                CollectionAssert.AreEqual(expectedErrors, scopeNode.Errors);
                CollectionAssert.AreEqual(expectedErrors, errorNode.Errors);

                textBox.ClearValidationError(validationError);
                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(stackPanel));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(textBox));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));
                Assert.AreSame(errorNode, Scope.GetNode(textBox));
                Assert.AreEqual(false, errorNode.HasError);
                Assert.AreNotSame(ErrorCollection.EmptyValidationErrors, errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Children);
            }
開發者ID:JohanLarsson,項目名稱:Gu.Wpf.ValidationScope,代碼行數:48,代碼來源:ScopeTests.StackpanelWithTextBoxes.cs

示例3: UpdatesError

        public void UpdatesError()
        {
            var textBox = new TextBox();
            var inputTypes = new InputTypeCollection { typeof(TextBox), typeof(Selector) };
            textBox.SetForInputTypes(inputTypes);
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            var errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);

            textBox.SetValidationError();
            Assert.AreEqual(true, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);

            textBox.ClearValidationError();
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
        }
開發者ID:gitter-badger,項目名稱:Gu.Wpf.ValidationScope,代碼行數:22,代碼來源:ScopeTests.TextBox.cs

示例4: UpdatesError

            public void UpdatesError()
            {
                var textBox = new TextBox();
                var stackPanel = new StackPanel();
                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection { typeof(TextBox), typeof(Selector) };
                stackPanel.SetForInputTypes(inputTypes);

                Assert.AreEqual(false, Scope.GetHasErrors(stackPanel));
                IErrorNode errorNode = (ScopeNode)Scope.GetErrors(stackPanel);
                Assert.AreEqual(null, errorNode);

                Assert.AreEqual(false, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);

                textBox.SetValidationError();
                Assert.AreEqual(true, Scope.GetHasErrors(stackPanel));
                errorNode = (ScopeNode)Scope.GetErrors(stackPanel);
                Assert.AreEqual(stackPanel, errorNode.Source);
                Assert.AreEqual(1, errorNode.Children.Count);

                Assert.AreEqual(true, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);

                textBox.ClearValidationError();
                Assert.AreEqual(false, Scope.GetHasErrors(stackPanel));
                errorNode = (ScopeNode)Scope.GetErrors(stackPanel);
                Assert.AreEqual(null, errorNode);

                Assert.AreEqual(false, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
            }
開發者ID:gitter-badger,項目名稱:Gu.Wpf.ValidationScope,代碼行數:38,代碼來源:ScopeTests.StackpanelWithTextBoxes.cs

示例5: UpdatesAndNotifiesError

            public void UpdatesAndNotifiesError()
            {
                var textBox = new System.Windows.Controls.TextBox();
                var inputTypes = new InputTypeCollection { typeof(System.Windows.Controls.TextBox), typeof(Selector) };
                Scope.SetForInputTypes(textBox, inputTypes);
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                var errorNode = (InputNode)Scope.GetNode(textBox);
                var errorArgs = errorNode.Errors.SubscribeObservableCollectionEvents();
                var nodeArgs = errorNode.SubscribePropertyChangedEvents();
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.IsEmpty(errorNode.Errors);
                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                textBox.SetValidationError(validationError);
                Assert.AreEqual(true, Scope.GetHasError(textBox));
                errorNode = (InputNode)Scope.GetNode(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.AreEqual(new[] { validationError }, errorNode.Errors);

                var expectedErrorArgs = new List<EventArgs>
                                   {
                                       new PropertyChangedEventArgs("Count"),
                                       new PropertyChangedEventArgs("Item[]"),
                                       new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, validationError, 0)
                                   };
                CollectionAssert.AreEqual(expectedErrorArgs, errorArgs, ObservableCollectionArgsComparer.Default);
                CollectionAssert.AreEqual(new[] { new PropertyChangedEventArgs(nameof(Node.HasError)) }, nodeArgs, PropertyChangedEventArgsComparer.Default);

                textBox.ClearValidationError(validationError);
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(errorNode, Scope.GetNode(textBox));
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.IsEmpty(errorNode.Errors);

                expectedErrorArgs.Add(new PropertyChangedEventArgs("Count"));
                expectedErrorArgs.Add(new PropertyChangedEventArgs("Item[]"));
                expectedErrorArgs.Add(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, validationError, 0));
                CollectionAssert.AreEqual(expectedErrorArgs, errorArgs, ObservableCollectionArgsComparer.Default);

                CollectionAssert.AreEqual(new[] { new PropertyChangedEventArgs(nameof(Node.HasError)), new PropertyChangedEventArgs(nameof(Node.HasError)) }, nodeArgs, PropertyChangedEventArgsComparer.Default);
            }
開發者ID:JohanLarsson,項目名稱:Gu.Wpf.ValidationScope,代碼行數:43,代碼來源:ScopeTests.TextBox.cs

示例6: Notifies

            public void Notifies()
            {
                var textBox = new System.Windows.Controls.TextBox();
                var textBoxEvents = textBox.SubscribeScopeEvents();
                Scope.SetForInputTypes(textBox, new InputTypeCollection { typeof(System.Windows.Controls.TextBox), typeof(Selector) });
                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                textBox.SetValidationError(validationError);
                var expectedEvents = new List<ScopeValidationErrorEventArgs>
                                         {
                                             new ScopeValidationErrorEventArgs(validationError, ValidationErrorEventAction.Added)
                                         };
                CollectionAssert.AreEqual(expectedEvents, textBoxEvents, ScopeValidationErrorEventArgsComparer.Default);

                textBox.ClearValidationError(validationError);
                expectedEvents.Add(new ScopeValidationErrorEventArgs(validationError, ValidationErrorEventAction.Removed));
                CollectionAssert.AreEqual(expectedEvents, textBoxEvents, ScopeValidationErrorEventArgsComparer.Default);
            }
開發者ID:JohanLarsson,項目名稱:Gu.Wpf.ValidationScope,代碼行數:17,代碼來源:ScopeTests.TextBox.cs

示例7: UpdatesErrors

            public void UpdatesErrors()
            {
                var textBox = new System.Windows.Controls.TextBox();
                var stackPanel = new StackPanel();
                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection { typeof(System.Windows.Controls.TextBox), typeof(Selector) };
                Scope.SetForInputTypes(stackPanel, inputTypes);

                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));

                Assert.AreEqual(false, Scope.GetHasError(textBox));
                var inputNode = (InputNode)Scope.GetNode(textBox);
                Assert.AreEqual(textBox, inputNode.Source);
                CollectionAssert.IsEmpty(inputNode.Children);
                CollectionAssert.IsEmpty(inputNode.Errors);

                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                textBox.SetValidationError(validationError);
                Assert.AreEqual(true, Scope.GetHasError(stackPanel));
                var scopeNode = (ScopeNode)Scope.GetNode(stackPanel);
                Assert.AreEqual(stackPanel, scopeNode.Source);
                Assert.AreEqual(1, scopeNode.Children.Count);
                CollectionAssert.AreEqual(new[] { validationError }, scopeNode.Errors);

                Assert.AreEqual(true, Scope.GetHasError(textBox));
                Assert.AreSame(inputNode, Scope.GetNode(textBox));
                Assert.AreEqual(textBox, inputNode.Source);
                CollectionAssert.IsEmpty(inputNode.Children);
                CollectionAssert.AreEqual(new[] { validationError }, inputNode.Errors);

                textBox.ClearValidationError(validationError);
                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));

                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(inputNode, Scope.GetNode(textBox));
                Assert.AreEqual(textBox, inputNode.Source);
                CollectionAssert.IsEmpty(inputNode.Children);
                CollectionAssert.IsEmpty(inputNode.Errors);
            }
開發者ID:JohanLarsson,項目名稱:Gu.Wpf.ValidationScope,代碼行數:41,代碼來源:ScopeTests.StackpanelWithTextBoxes.cs


注:本文中的System.Windows.Controls.TextBox.ClearValidationError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。