Silverlight 3 DataForm Validation with Templates
I have an SL3 application in which I am using DataForm to enter data. I want my form to look the way I like, so I use <dataControls:DataForm.EditTemplate>
and inside the template I have a nice form design.
The main problem is that inside the template, I have to use regular controls (like TextBox) instead of "field" controls (like DataFormTextField). they both work pretty much the same with a big difference when they get checked.
if I throw an exception on the property setter they are bound to, they both show the correct red sign and error, but if I decorate the property with validation attributes (for example [Required(ErrorMessage = "can't be empty!")]
), then only the DataFormTextField and the TextBox control show an error. in both cases my ErrorSummary control has an error in its collection, so I can see that the error is being taken into account ...
Any help is appreciated.
a source to share
Are you using a template field?
<df:DataFormTemplateField FieldLabelContent="Year">
<df:DataFormTemplateField.DisplayTemplate>
<DataTemplate>
<TextBox Text="{Binding Year}" HorizontalAlignment="Left" />
</DataTemplate>
</df:DataFormTemplateField.DisplayTemplate>
<df:DataFormTemplateField.EditTemplate>
<DataTemplate>
<TextBox Text="{Binding Year}" HorizontalAlignment="Left" />
</DataTemplate>
</df:DataFormTemplateField.EditTemplate>
</df:DataFormTemplateField>
a source to share