Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <TextBox...
- <TextBox.Text>
- <Binding Path ="LastName" UpdateSourceTrigger="PropertyChanged">
- <Binding.ValidationRules>
- <local:StringRequiredValidationRule />
- </Binding.ValidationRules>
- </Binding>
- </TextBox.Text>
- this.AddHandler(Validation.ErrorEvent,new RoutedEventHandler(OnErrorEvent));
- private int errorCount;
- private void OnErrorEvent(object sender, RoutedEventArgs e)
- {
- var validationEventArgs = e as ValidationErrorEventArgs;
- if (validationEventArgs == null)
- throw new Exception("Unexpected event args");
- switch(validationEventArgs.Action)
- {
- case ValidationErrorEventAction.Added:
- {
- errorCount++; break;
- }
- case ValidationErrorEventAction.Removed:
- {
- errorCount--; break;
- }
- default:
- {
- throw new Exception("Unknown action");
- }
- }
- Save.IsEnabled = errorCount == 0;
- }
- int count = 0;
- private void LayoutRoot_BindingValidationError(object sender, ValidationErrorEventArgs e)
- {
- if (e.Action == ValidationErrorEventAction.Added)
- {
- button1.IsEnabled = false;
- count++;
- }
- if (e.Action == ValidationErrorEventAction.Removed)
- {
- count--;
- if (count == 0) button1.IsEnabled = true;
- }
- }
Add Comment
Please, Sign In to add comment