idataerrorinfo

How can I define a IDataErrorInfo Error Property for multiple BO properties

雨燕双飞 提交于 2019-12-03 12:27:50
问题 I'm starting to implement validation in my WPF project via the IDataErrorInfo interface. My business object contains multiple properties with validation info. How do I get a list of ALL the error messages associated with the object. My thought is that thats what the Error property is for, but I cannot track down anyone using this for reporting on multiple properties. Thanks! public string this[string property] { get { string msg = null; switch (property) { case "LastName": if (string

Exception validating data with IDataErrorInfo with a MVVM implementation

落花浮王杯 提交于 2019-11-30 16:00:23
问题 I'm trying to validate data in my MVVM application using IDataErrorInfo, but I'm running into some problems. When I set my TextBox with an invalid value, the validation works fine. But after I set the value of the TextBox to a valid value and I get this exception: A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll System.Windows.Data Error: 16 :

Exception validating data with IDataErrorInfo with a MVVM implementation

喜欢而已 提交于 2019-11-30 15:45:32
I'm trying to validate data in my MVVM application using IDataErrorInfo, but I'm running into some problems. When I set my TextBox with an invalid value, the validation works fine. But after I set the value of the TextBox to a valid value and I get this exception: A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll System.Windows.Data Error: 16 : Cannot get 'Item[]' value (type 'ValidationError') from '(Validation.Errors)' (type

Prism IDataErrorInfo validation with DataAnnotation on ViewModel Entities

烈酒焚心 提交于 2019-11-30 14:25:16
问题 I'm implementing data validation in WPF using the Prism MVVM framework. I'm using clean data Entities in the ViewModel which are being bound to the presentation layer. <TextBox Text="{Binding User.Email, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" /> I've implemented a generic implementation of IDataErrorInfo in a base ViewModel class that runs validation against the DataAnnotation attributes on my Entity (in this case User). The issue is that when binding to an Entity,

Prism IDataErrorInfo validation with DataAnnotation on ViewModel Entities

[亡魂溺海] 提交于 2019-11-30 10:51:28
I'm implementing data validation in WPF using the Prism MVVM framework. I'm using clean data Entities in the ViewModel which are being bound to the presentation layer. <TextBox Text="{Binding User.Email, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" /> I've implemented a generic implementation of IDataErrorInfo in a base ViewModel class that runs validation against the DataAnnotation attributes on my Entity (in this case User). The issue is that when binding to an Entity, the WPF framework looks for IDataErrorInfo on the Entity and not the ViewModel which is where I want

How to validate child objects by implementing IDataErrorInfo on parent class

感情迁移 提交于 2019-11-30 08:50:20
问题 I am developing a WPF Application using MVVM Architecture. I am an amateur in WPF so bear with me.. I have two model classes. Parent class has an object of another (child) class as its property. (i mean nested objects and not inherited objects) For instance, consider the following scenario. public class Company { public string CompanyName {get; set;} public Employee EmployeeObj {get; set;} } public class Employee { public string FirstName {get; set;} public string LastName {get; set;} } I

Using IDataErrorInfo in M-V-VM

爷,独闯天下 提交于 2019-11-30 08:09:00
问题 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

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

淺唱寂寞╮ 提交于 2019-11-30 06:42:48
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}"> <TextBlock Text="!" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Bold" Foreground=

IDataErrorInfo : How to know if all properties are valid?

白昼怎懂夜的黑 提交于 2019-11-29 19:22:42
问题 I have a WPF application( .Net 3.5 ) which uses the IDataErrorInfo on the ViewModel to validate input. It works great, the usercontrol get the correct UI feedback. The problem is that the user can still change the selected element, or save this element. So my question is: How can I know that all my properties are valid? Or at least that all my displayed values are valid. The goal is to bind some IsActive on this result 回答1: From your comment on your implementation of IDataErrorInfo change

DataAnnotations vs IDataErrorInfo

爱⌒轻易说出口 提交于 2019-11-29 19:22:35
问题 DataAnnotations vs IDataErrorInfo Pros and Cons of both? Benefits of one over the other? (especially related to MVC) 回答1: Late entry to the discussion as I do not want to start a new question. Where I am coming from is to determine the best practice to apply to a medium size ASP.NET MVC project. Let me first summarise our options :- 1) IDataErrorInfo is simple to implement. All you need is to derive IDataErrorInfo in your Model class. The catch is that you are letting your model binding to be