Using IDataErrorInfo and setting Validation.HasError style - wpf

In WPF using IDataErrorInfo and Style I want to create form where I can provide end user three different status while validating data
To make the scenario more clear
1) I have textbox next to it I have icon which provides end user what kind of input textbox expects - Initial status with information icon
2) As soon as user enter data it validates it and decides whether it is valid or not
- most of the time it will show cross (X) icon saying invalid data
3) As it is validating on UpdateSourceTrigger="PropertyChanged" it will turn cross icon to green check mark as soon as it gets validated
i.e
[ ] i (tooltip- Any valid user name )
[Ga ] X (tooltip- Invalid user name. Must be 5 char long)
[Gaurav ] * (it will show only correct icon, meaning valid value)
How can I achieve this using IDataErrorInfo and Style, I tried doing that but as soon as my form gets loaded it invalidates all the data and shows cross icon at the first time. I want to show different tooltip and different icon for three states (Initial info, Invalid data, Valid data)

IDataErrorInfo does not contain any means of representing three states. It only knows "error" and "no error".
The best solution may be to circumvent the use of IDataErrorInfo via the following:
Create a property for each validated field that provides the three-state status for its related field.
Bind ContentControls in the view to these three-state properties.
Set a single style for all of these new ContentControls.
Use Triggers in the Style to assign the ContentControl.ContentTemplate property for the error state and the valid state. For the initial state, use a Setter in the Style itself to display nothing.
You may also have to create properties for each field's tooltip text as well.

you can find a great example here WPF Apps With The Model-View-ViewModel Design Pattern

Related

Show placeholder text for unchanged properties in a PropertyGrid

I am trying to figure out how to add placeholder string value on every property inside a property grid that was not changed from the user.
So let's say you are trying to edit some object when you get prompted to do so you will get the following form.
If you changed the color property for example the result would be the following.
I tried to see if there is an attribute but it seems that there is not. DefaultValue is not suitable because the message is a string and the underlying property could be anything.
The question is if this is possible using combinations of Editors and TypeConverters.
Thanks.

Vaadin: Reload ComboBox List while typing

I got a ComboBox in Vaadin and want to reload (from db) the set of entries in the dropdown list while typing in the text field of the ComboBox. I always got the exception:
java.lang.IllegalStateException: A connector should not be marked as dirty while a response is being written.
I tried to lock the session (getUI().getSession().getLockInstance().lock();), but it didn't help.
Is it possible to dynamically set/load the selection list of a ComboBox?
Cheers
Stefan
why do you want to change the content from DB as the user type? you'll get a postback and a query every key the user presses... isn't better to use the standard combo feature (which tries to autocomplete the value given what the user is typing)?
Anyway, if you really need this feature, you may extend the standard behaviour of combo extending the container behind the combo, as the data shown is taken from a container.

jeasyui - Validating combobox input

I am using jeasyui editable combobox. How to restrict the user to type only valid values.
for example, if my list is containing,
C
Cplus
Java
if the user type vb and tries to save, its saving with value "0".
You can set the combobox as a validatebox. And define your rule to validate.
for more info, please hit easyui validate box

How do you validate the data in your ViewModel in the MVVM pattern?

I listened to this herding code podcast on MVC, MVP, MVVM yesterday and was struck by the idea of sending your whole ViewModel object to a validator which does nothing but validate all the fields in it and send it back.
has anyone implemented that type of validation pattern?
how did it look technically?
I am thinking of extending this idea by also having a "FormPreparer" which receives the whole ViewModel after the Model data, field metadata, and other user and context data is fed into it, then this "FormPreparer" prepares all the fields on the form which will be on the View so that e.g.
date fields are represented by DatePicker controls
e-mail fields are represented by textBoxes with e-mail validation
and e.g. the Customer field is a dropdown of customers
the metadata defines these things about each field:
type (text, date, date/time, duration, email, url, customer)
control (textbox, multiline textbox, dropdown, radiobuttons, checkbox, clickbutton)
label (e.g. "First Name")
helptext (e.g. "this is the number you find on the top of Form 4A")
example ("#123ABCD")
display tab (e.g. for forms that consist of a number of tab areas)
display area (e.g. for forms that group fields into areas)
display order (e.g. the order of the fields in the group)
value (e.g. "Jim")
autosuggest data (an array of names which needs to be displayed when the user begins to type)
field status (readonly, edit, hide)
the "FormPreparer" would combine all this information and then present data to the View which:
shows all form data in appropriate controls (dates as datepickers, descriptions in multiline textboxes, etc.)
takes care of all validation automatically
would only display fields which the current user is allowed to see and would only let him edit data which he is allowed to edit
etc.
Has anyone programmed a WPF/MVVM application along these lines?
No. I'm working on a WPF/MVVM project, but we have not taken such a generic approach to validation. We are creating a custom validation method in each view model with validation logic specific to each view model.
A generic validation routine that could be used for all view models would be great.

Cannot tab out of databound Winforms dropdown list

This is a bit of a strange one, but I've been struggling for a few hours now and I can't understand what is happening.
I was wondering if anyone else has experienced this problem, and can perhaps explain it. I'm building a simple Winforms app and trying to use many of the built in controls.
Basically, I've got a form with a user control and some data capture fields. 3 of the fields are dropdown lists and on the user control I have a bindingSource control that binds directly to a Product class.
At run time I provide an instance of the Product class to the BindingSource and the class contains a property of ProductType. For simplicity I also added a List<ProductType> ProductTypes to the Product Class which loads itself when queried, which means I can just use the same bindingSource and choose the ProductTypes Data Member as the Datasource for the dropdownlist.
Upon running the form, the list binds perfectly and I can see all the product types listed, and I can select one and tab or click to the next field. But obviously the selected value won't bind because I've not chosen any bindings-SelectedValue for the dropdown, only a datasource. As soon as I make sure that the drop down modifies the instance of the Product by binding to the Bindings-SelectedValue, and then run the form, the list still gets populated perfectly and I can tab through the controls as long as I don't make a selection from the dropdown. If I make a selection from the dropdown then the dropdown holds focus. I cannot tab out for love or money and can't even click cancel button on the form, the close button top right is the only button I can click which works and I can't click any other field or dropdown. This affects all three dropdowns as soon as a selection is made.
Anyone have any ideas what I'm missing?
I have tried changing a few things and had some success by feeding the dropdown values a string[] instead of a member of an object. That seems to work, but defeats the object of using databinding doesn't it?
Any help appreciated!
Just guessing here, because I don't have time to set up a test and confirm right now, but are you doing any validating? I seem to remember that data-bound controls won't let you leave if the contents don't validate. Even if you aren't explicitly, try setting CausesValidation to False to see if there's any sort of validation going on behind the scenes, that might at least give you a hint.
Thanks for the input on this, helped me wrap my head around this.
In my case, it turns out that an exception was being thrown in one of the EventHadlers for my ComboBox.Validating event. It was hard to track down, because the IDE didn't show me that exception. I was able to modify the Exception behavior (in the debug menu) and have it show me any InvalidOperationException that was being thrown, and then I was able to track it down.
As Tom suggested, turning off CuasesValidation was the ticket to figuring it out.
For Infragisticst Dropdowns (may not be true for other winform dropdowns): If you have "LimitToList" set to true you can be stuck in a dropdown that you can't get out of without realizing it. Use the ItemNotInList even to trigger a warning message.

Resources