idataerrorinfo

IDataErrorInfo in winforms

懵懂的女人 提交于 2019-11-29 13:55:37
问题 Can IDataError info be used properly in a winforms application? In the past I was doing my binding the usual way(1) and did the validation in the OnValidating event of the particular control. I would like to move the data validation to the domain model so that I can easily swap out user interfaces and so that all of the logic is in one place. I was looking into IDataErrorInfo but everything I find deals with WPF and the app in development is strictly a winforms app. I also noticed that the

Error template is displayed above other controls, when it should be hidden

↘锁芯ラ 提交于 2019-11-29 06:23:10
问题 I'm trying to implement validation in my WPF application using the IDataErrorInfo interface, and I've encountered a not-so-desirable situation. I have this template which is used when a control fails to validate <ControlTemplate x:Key="errorTemplate"> <DockPanel LastChildFill="true"> <Border Background="Red" DockPanel.Dock="Right" Margin="5,0,0,0" Width="20" Height="20" CornerRadius="10" ToolTip="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}">

Using IDataErrorInfo in M-V-VM

只愿长相守 提交于 2019-11-29 06:12:12
If my domain objects implement IDataErrorInfo, and I am using M-V-VM, how do I propagate errors through the ViewModel into the View? If i was binding directly to the model, I would set the "ValidateOnExceptons" and "ValidateOnErrors" properties to true on my binding. But my ViewModel doesn't implement IDataErrorInfo. Only my model. What do I do? Clarification I am dealing with an existing codebase that implements IDataErrorInfo in the domain objects. I can't just implement IDataErrorInfo in the my view model. You can implement IDataErrorInfo additionally in your VM and route the calls to the

using IDataErrorInfo in asp.net mvc

≯℡__Kan透↙ 提交于 2019-11-29 02:34:55
I've got a simple address entry app that I'm trying to use the IDataErrorInfo interface as explained on the asp.net site . It works great for items that can be validated independently, but not so well when some items depend on others. For example, validating the postal code depends on the country: private string _PostalCode; public string PostalCode { get { return _PostalCode; } set { switch (_Country) { case Countries.USA: if (!Regex.IsMatch(value, @"^[0-9]{5}$")) _errors.Add("PostalCode", "Invalid Zip Code"); break; case Countries.Canada: if (!Regex.IsMatch(value, @"^([a-z][0-9][a-z]) ?([0-9

Issue with WPF validation(IDataErrorInfo) and tab focusing

最后都变了- 提交于 2019-11-28 21:33:57
I have a TextBox bound to a property of an object which implements IDataErrorInfo . I set up the Validation.ErrorTemplate of the TextBox , and it works fine. The problem is that I have these on a TabControl , and the validation template doesn't display any more if I change the tab to another one and then come back to the initial tab (where the TextBox is). It looks like it is validated(like the value is correct), but actually it is not. This is the IDataErrorInfo object - note that a "correct" value is a string with a length of 2: public class Presenter : IDataErrorInfo { public Presenter() {

WPF command binding with input validation - how to enable the “save” button only if all input is valid

时光总嘲笑我的痴心妄想 提交于 2019-11-28 11:08:40
问题 In my ViewModel I have implemented IDataErrorInfo interface (along with INotifyPropertyChanged). Input validation works as intended, I have no problems there. I have this property as part of IDataErrorInfo public string Error { get { return this[null]; } } To my understanding, Error should be empty if all validated inputs pass validation, so I pass this as my CanExecute method return !string.IsNullOrEmpty(Error); But, my "save" button never gets enabled. My gues is that CanExecuteChanged

How can I validate multiple properties when any of them changes?

霸气de小男生 提交于 2019-11-28 06:24:19
I have two date fields: StartDate and EndDate. StartDate must be earlier than EndDate. If the user changes the StartDate to something greater than the EndDate, a red border appears around that DatePicker, and vise versa. If the user changes the 2nd box so that the date range is now correct, the 1st box still has the Validation Error. How can I validate both date fields when either one of them changes? I'm using IDataErrorInfo public string GetValidationError(string propertyName) { switch (propertyName) { case "StartDate": if (StartDate > EndDate) s = "Start Date cannot be later than End Date";

WPF DataGrid validation errors not clearing

扶醉桌前 提交于 2019-11-27 12:37:17
So I have a WPF DataGrid , which is bound to an ObservableCollection . The collection has validation on its members, through IDataErrorInfo . If I edit a cell in a way so as to be invalid, and then tab away from it before hitting enter, then come back and make it valid, the cell will stop showing invalid, however, the "!" at the head of the row will still be there, and the ToolTip will reference the previous, invalid value. Not using Mode=TwoWay for DataGridTextColumns solves one version of the problem, however it seems that this problem can appear out of nowhere for other reasons as well.

How can I validate multiple properties when any of them changes?

左心房为你撑大大i 提交于 2019-11-27 05:40:06
问题 I have two date fields: StartDate and EndDate. StartDate must be earlier than EndDate. If the user changes the StartDate to something greater than the EndDate, a red border appears around that DatePicker, and vise versa. If the user changes the 2nd box so that the date range is now correct, the 1st box still has the Validation Error. How can I validate both date fields when either one of them changes? I'm using IDataErrorInfo public string GetValidationError(string propertyName) { switch

How to use IDataErrorInfo.Error in a WPF program?

爱⌒轻易说出口 提交于 2019-11-26 12:43:55
问题 I have an object like that: public class Person : IDataErrorInfo { public string PersonName{get;set;} public int Age{get;set;} string IDataErrorInfo.this[string propertyName] { get { if(propertyName==\"PersonName\") { if(PersonName.Length>30 || PersonName.Length<1) { return \"Name is required and less than 30 characters.\"; } } return null; } } string IDataErrorInfo.Error { get { if(PersonName==\"Tom\" && Age!=30) { return \"Tom must be 30.\"; } return null; } } } Binding the PersonName and