ComboBox And Validation Rules

Topics: Developer Forum
Apr 21, 2008 at 5:41 AM
Can anybody please show a sample or how to do it correctly from you experience or what you have done in this case ,where you have a combobox and you have a rule like (below) applied to the combo

<property name="Address">
<rule errorMessage="Please select a Address."

mainly this rule is to make sure that a user selects a say address from the combobox and does not leave it empty or null.I have something like

<Grid DataContext="{Binding Path=BussinessObject}">
<ComboBox x:Name="cbxAddress" SelectedValue="{Binding Path=Address,ValidatesOnExceptions=True}"

for the control

When the user click save a message is displayed to him,the issue is that even if I have a value selected on the form in the combo the message appears to me.
Apr 21, 2008 at 12:16 PM
Edited Apr 21, 2008 at 12:17 PM
I suspect the problem you have is not setting the UpdateSourceTrigger in the Binding.
I have added a ComboBox sample to the QSWPFApplicationCSharp project in the latest checkin
In it I use the following XAML to bind to the ComboBox

		<Binding Source="{StaticResource AvailableGenders}"/>
		<ValidationFrameworkWPF:ValidationBinding Path="Gender"  UpdateSourceTrigger="PropertyChanged" />

You should also check that when you are changing the selected item that it is writing back to the business object. To do his you should set a break point on the set of the "Address" property and change the selected value of the combobox.

If you are still having problems send me a sample solution illustrating your problem.