473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

What is the best approach to implementing the IDataErrorInfo Interface

Frinavale
9,735 Expert Mod 8TB
I have a ViewModel class that implements the IDataErrorInfo Interface.

In each of the ViewModel's properties set code blocks I validate the value passed in. If it fails the validation I call a method called AddError to add an error for the property. The AddError method adds an item into the underlying data type that I'm using to manage the errors for the IDataErrorInfo Interface...which is a Dictionary(Of String, List(Of String)).

Currently things are working well during data entry. If the user enters invalid values for a property, the WPF FrameworkElement that is used to input the data is highlighted with the ToolTip set to the error message.

Now, here's my problem.

Say my object contains invalid fields from the start....

For example, if I have a Person class with a required field "Name" and I create a new instance of the Person class. The "Name" Field will not be highlighted as an "error" because the Name Property's set method hasn't been called yet. Everything "looks" valid to the page.

So, I put validation into the property's get as well.

This seems to works bu it feels like a hack.

And some property validation has to be done by the model (as opposed to the ViewModel that I'm working with). The Model bubbles up the appropriate error message that should be set but I can't get the error message unless I set the Model's property.

Any advise on the best approach to implementing the IDataErrorInfo interface would be really really appreciated.

Thanks!

-Frinny
Feb 17 '11 #1
1 2941
Frinavale
9,735 Expert Mod 8TB
I figured out something that doesn't feel like a hack.

I also probably should have mentioned that I have a base class that all my ViewModel inherit from. It is in this base class that I am implementing the IDataErrorInfo Interface.

What I ended up doing was adding a new MustOverride method to the base ViewModel class called "Validate" that validates the property name supplied to it. If the validation fails then it adds an entry into my underlying errors dictionary.

I call the validate method in the Item property (that implements the IDataErrorInfo.Item property).

This way each derived class can contain it's own validation code and I can be sure that the method exists because it's part of the base ViewModel class.

If this isn't the best approach, please let me know.

-Frinny
Feb 17 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: milesm | last post by:
I've spent the last 3 hours reading various MSDN articles, other site articles and news group postings and was wondering what the best approach to my situation would be since I'm unable to come up...
4
by: David Pinx | last post by:
Greetings, I will be developing an application that will have two versions, a web application to be deployed at the client side and a windows application. The question is, what would be the...
4
by: Rob R. Ainscough | last post by:
For ASP.NET 2.0 (or 1.1) what is the best approach to implementing a processing message or graphic while my task is working away? Thanks, Rob.
1
by: ProjectNut | last post by:
what is the syntax for implementing an interface in a generic class that has a constrained base class example: class myclass<T>: mybase<T> where T: IComparable { } Now, I want myclass<T>...
4
by: Brian | last post by:
I really want to use the IDataErrorInfo interface. I'm using it now in combination with an ErrorProvider and this seems really good. But the downside: IDataErrorInfo wants to use a string...
3
by: David Veeneman | last post by:
I'm new to VB.NET, and I am translating an object model from C# to VB.NET, and I have come across an odd problem implementing an interface. The interface is a custom interface, IDrillDown, which...
0
by: ZA_AJR | last post by:
Hi All I have a class (aClass, derived from aBaseClass) with implements an interface IMyInterface. aClass also has a private member of type aNotherClass which raises various events. I would like...
2
by: --== Alain ==-- | last post by:
Hi, I'm currently working under VC++.NET 2005 and i'm deriving my custom control from ListView. I need your feedback to know in which direction should i develop this control. I've seen on...
1
by: vinoda2005 | last post by:
Hi everybody, Can anybody tell me what is the use of implementing closeable interface by Input and Output streams when there is already close() method in them???? Please tell me..... ...
5
by: gw7rib | last post by:
I'm writing a program which has "notes" - these can appear on the screen as windows with text in. It is possible to create an "index note" - at present, this will contain a list of the titles (or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.