R – Silverlight 3 validation DataForm with templates

dataformsilverlight-3.0validation

I have a SL3 application in which I'm using DataForm for my data entry. I want my form to look in the way I like it, so, I use <dataControls:DataForm.EditTemplate> and inside the template I have my good looking form design.

the main issue is, inside the template I have to use normal controls (like TextBox) instead of the "field" controls (like DataFormTextField). they both work almost the same with the big difference when it gets to validation.

if I throw an exception in the setter of the property to which they are bound, they both show the proper red sign and error, but if I decorate the property by validation attributes (for example [Required(ErrorMessage = "can't be empty!")]), only the DataFormTextField control and not the TextBox control will show the error. in both cases my ErrorSummary control has the error in its collection, so I can see the error is being taken into account…

Any help is appreciated.

Best Answer

Are you using the 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> 
Related Topic