views:

315

answers:

1

I have a WPF sub window with some input controls that the user has to correctly fill before pressing Ok button.

I have already implemented the interface IDataErrorInfo to validate all properties bound to UI Controls.

Now I would like that the IsEnabled property of Ok button is True only if ALL controls are valid, otherwise it has to be set to False.

It should be easy but I cannot find the correct solution. Do you have any suggestion?

Thanks in advance!

+1  A: 

Ciao ;-)

I think you could bind the IsEnabled property of the button to (e.g.) the IDataErrorInfo.Error property of your data through a IValueConverter (that you have to implement) that converts from string to bool (e.g if the value if String.Empty than return true).

Another solution is to use Commands and have this logic enclosed in the CanExecute: in this way you just have to associate the Command with your Button. HTH

Fabrizio C.
@Fabriziothank you Fabrizio, I'll try your suggestions and come back with the result as soon as possible ;)
marco.ragogna
I tried the implementation using the IDataErrorInfo.Error property. Practically I have bound that to the IsEnable button property with the converter, but it does not work. Probably I should implement an event and bound it in the button triggers. Not sure about it.
marco.ragogna