本文整理汇总了C#中System.Windows.Controls.TextBox.SetValidationError方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.SetValidationError方法的具体用法?C# TextBox.SetValidationError怎么用?C# TextBox.SetValidationError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.TextBox
的用法示例。
在下文中一共展示了TextBox.SetValidationError方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextBoxSetSetForInputTypesTextBox
public void TextBoxSetSetForInputTypesTextBox()
{
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));
CollectionAssert.IsEmpty(Scope.GetErrors(textBox));
var errorNode = (InputNode)Scope.GetNode(textBox);
Assert.AreEqual(textBox, errorNode.Source);
Assert.AreEqual(false, errorNode.HasError);
CollectionAssert.IsEmpty(errorNode.Children);
CollectionAssert.IsEmpty(errorNode.Errors);
var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
textBox.SetValidationError(validationError);
var expectedErrors = new[] { validationError };
Assert.AreEqual(true, Scope.GetHasError(textBox));
CollectionAssert.AreEqual(expectedErrors, Scope.GetErrors(textBox));
Assert.AreSame(errorNode, Scope.GetNode(textBox));
Assert.AreEqual(true, errorNode.HasError);
Assert.AreEqual(textBox, errorNode.Source);
CollectionAssert.IsEmpty(errorNode.Children);
CollectionAssert.AreEqual(expectedErrors, errorNode.Errors);
}
示例2: 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);
}
示例3: TextBoxSetSetForSelectorAndSlider
public void TextBoxSetSetForSelectorAndSlider()
{
var textBox = new System.Windows.Controls.TextBox();
var inputTypes = new InputTypeCollection { typeof(Selector), typeof(Slider) };
Scope.SetForInputTypes(textBox, inputTypes);
Assert.AreEqual(false, Scope.GetHasError(textBox));
Assert.AreEqual(ValidNode.Default, Scope.GetNode(textBox));
var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
textBox.SetValidationError(validationError);
Assert.AreEqual(false, Scope.GetHasError(textBox));
Assert.AreEqual(ValidNode.Default, Scope.GetNode(textBox));
}
示例4: 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);
}
示例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);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}