Validation using multibinding

Topics: Prism v4 - WPF 4
Feb 14, 2012 at 4:08 PM

After spending the best part of two days combing the web and trying to get my head around this, I have to ask for help!

I have a scenario where I have a simple form in my view where the user enters some data and then hits a search button.  In an ideal world, if they've left any fields blank (or done something wrong, like put numbers in a text field) they won't be allowed to move on to the results screen and will be given some hint about what is wrong.

I've seen various ways of performing validation, but I can't find any examples that use Multibinding.

I have 4 text boxes in the view that a user can enter data into, then when they hit the button, I'd like to see some feedback if necessary, or move onto the results screen. My xaml is similar to that below, I think I need to implement IDataErrorInfo in the view model (my button commands are split out into separate files from the view model and I'm not sure if that is the best thing to do or not). I have tried implementing IDataErrorInfo, and I can't seem to get it to validate.

  <Button Command="{Binding ShowModuleAppConflictSearchResults}" Content="Search" Grid.Row="2" Height="23"  Margin="0,28,12,0" Name="btnSearch" VerticalAlignment="Top" Width="75" HorizontalAlignment="Right">
                <MultiBinding Converter="{StaticResource conflictSearchConverter}" >
                    <Binding Path="Text" ElementName="txtone"   ></Binding>
                    <Binding Path="Text" ElementName="txttwo"/>
                    <Binding Path="Text" ElementName="txtthree"/>
                    <Binding Path="Text" ElementName="date"></Binding>


Feb 15, 2012 at 5:54 PM


I believe you could find the Commanding QuickStart provided by Prism useful, although it does not use Multibinding, it could be taken as a starting point reference to achieve this kind of scenarios, which also implements IDataErrorInfo interface to perform data validation.

Additionally you could find the following resources useful:

I hope you find this handy,

Agustin Adami

Feb 20, 2012 at 10:25 AM

Thanks Agustin!


After re-reading chapter 5 (and much swearing as the code quotes there seemed to be silverlight only!) I took the Commanding QuickStart to bits and put it back together again to see if I could get mine working.  This helped with 3 of the four fields that needed validation, which are text boxes.  The fourth was a little more interesting - the control to be validated is a date picker, so getting the xaml styling correct to outline it on error took a bit of digging into the documentation on the MSDN website to find out  about validation error templates.


I suspect I've kind of used a sledge hammer to crack a nut - like the quick start sample I use a delegate command to check if things are indeed valid, and I then go on to call another command from there to move on and carry out my search.


Thanks once again