idataerrorinfo

How to set property in IDataErrorInfo validator from Xaml

When using IDataErrorInfo in WPF is there a way to pass parameters to the validator. For instance I have a DueDate Datepicker. When validating for a new task I want to restrict the date allowed to today or later but when editing I need to allow for DueDates before today since a task can be edited that is past due. My DatePicker in Xaml ...

unit testing IDataErrorInfo with tryupdatemodel in MVC

Hi, I'm trying to unit test a controller action in which I call tryupdatemodel, but the validation does not fire. When I run my application the validation occurs and is fine. My guess is the the model binder is not loaded in test scenarios, how can I test my action ? here is the code Company object public partial class Company : ID...

How do I unit test errors in an IDataErrorInfo business object?

I am writing (attempting to write) unit tests for a WPF application. The business objects that the UI binds to implement IDataErrorInfo, such that when I set ValidatesOnDataErrors=True in my View xaml, the error indexer (this[]) is called anytime the setter for the bound business object is called. That part is great. Now if I call th...

Problem with WPF validation(IDataErrorInfo) and tab focusing.

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...

pass Validation error to UI element in WPF?

I am using IDataErrorInfo to validate my data in a form in WPF. I have the validation implemented in my presenter. The actual validation is happening, but the XAML that's supposed to update the UI and set the style isn't happening. Here it is: <Style x:Key="textBoxInError" TargetType="{x:Type TextBox}"> <Style.Triggers>...

IDataErrorInfo with ValueConverter

I'm somehow doing it wrong, but I can't figure it out: I have a model like this: public class Person : IDataErrorInfo { public DateTime Birthdate { get { return _birthdate; } set { if (!Valid(value)) AddError("Birthdate", "Birthdate not valid"); _birthdate = value; } } } A ValueConverter like this...

WPF Validation & IDataErrorInfo

A note - the classes I have are EntityObject classes! I have the following class: public class Foo { public Bar Bar { get; set; } } public class Bar : IDataErrorInfo { public string Name { get; set; } #region IDataErrorInfo Members string IDataErrorInfo.Error { get { return null; } } string IDataE...

IDataErrorInfo: Validating when page submitted.

I am creating a WPF application that will use IDataErrorInfo data validation, which my business objects implement. I have been working with this demo from a blog post to understand ValidatesOnDataErrors. The demo is a trivial app that binds a couple of text boxes to a Contact object and implements IDataErrorInfo validation, using Valida...

WPF Validation with ContentPresenter

Hi, I have a WPF user control which needs to validate some fields. It is bound to a class implementing IDataErrorInfo. When I set the user control as the content of my ContentPresenter in another, already open, window, I can see validation occurring, and error messages being returned, however, I don't get any validation adorner - e.g....

Validation.HasError attached property

Did I miss something? 1- Style <Style TargetType="{x:Type TextBox}"> <Style.Triggers> <DataTrigger Binding="{Binding Path=Validation.HasError}" Value="true"> <Setter Property="BorderBrush" Value="Blue" /> </DataTrigger> </Style.Triggers> <Setter Property="MinWidth" Value=...

IDataErrorInfo vs ValidationRule vs Exception

Can anyone tell me which is a better approach for Validation in WPF. 1. Implementing IDataErrorInfo 2. Creating ValidationRule 3. Throwing Exceptions in terms of performance, memory leaks, code maintainability and re-use. ...

Problem with validation and multibinding

Hi, In my WPF application I use the following xaml: ... <TextBox services:TextBoxService.IsFocused="{Binding Path=IsSelected, Mode=OneWay}" FocusVisualStyle="{x:Null}"> <MultiBinding Converter="{StaticResource mconv_operableToString}" UpdateSourceTrigger="PropertyChanged"> <Binding Path...

asp.net mvc IDataErrorInfo validation when using ViewModel

I have used IDataErrorInfo Validation for my Model. But when I use these model classes inside a view model, the validation does not happen. sample viewmodel below public class CategoryViewModel { // Category class with IDataErrorInfo public Category category { set; get; } // Subcategory class with IDataErrorInfo pu...

Exception validating data with IDataErrorInfo with a MVVM implementation

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' oc...

How does IDataErrorInfo work?

I'm currently looking into validation for my WPF app and seen the mention of IDataErrorInfo. However there are few guides to how to use it and worse there are none who explain how it works. On MSND.com site this is givin' MSDN public class Person : IDataErrorInfo { private int age; public int Age { get { return ag...

Validation using IDataError

I have the following validation method in my viewmodel (example is showing only one column, "ItemNumber"): public bool IsValid { get { foreach (string property in ValidatedProperties) if (GetValidationError(property) != null) return false; return true; } } static readonly string[] ValidatedProperties = { ...

IDataErrorInfo on ObservableCollection

I have a viewmodel that implements IDataError. In the viewmodel I have an ObservableCollection. The ObservableCollection populates a datagrid in my view: // the list that populates the datagrid public ObservableCollection<ProjectExpenseItemsDto> ListOfProjectExpenseItems { get { return listOfProjectExpenseItems; } ...

how to fire Validation on a property of a calss used by a HierarchicalDatatemplate instead of firing it on my viewModel properties?

Hello Everyone. the problem i have is somewhat difficult to explain i will try my best: i am using a custom control called "TasklItem" (derived from Panel). this control renders itself hierarchically in a treeview using following HierarchicalDataTemplate: <Grid Name="TaskItemTempl...

.Net MVC2 How to add error to ModelState when using custom ValidationAttribute - Solved with IDataErrorInfo

I have the following ValidationAttribute class [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public sealed class DateValidationAttribute : ValidationAttribute { public DateValidationAttribute(string leftDateProperty, CompareOperator compareOperator, string rightDateProperty, string errorMessage) ...

How to validate child objects by implementing IDataErrorInfo on parent class

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 C...