带模板的 Silverlight 3 验证 DataForm

发布于 2024-07-20 12:50:52 字数 516 浏览 11 评论 0原文

我有一个 SL3 应用程序,其中使用 DataForm 进行数据输入。 我希望我的表单看起来像我喜欢的那样,因此,我使用 并且在模板内我有漂亮的表单设计。

主要问题是,在模板内我必须使用普通控件(如 TextBox)而不是“字段”控件(如 DataFormTextField)。 它们的工作原理几乎相同,但在验证时却存在很大差异。

如果我在它们所绑定的属性的设置器中抛出异常,它们都会显示正确的红色符号和错误,但是如果我通过验证属性来装饰该属性(例如 [Required(ErrorMessage = "can'不能为空!")]),只有 DataFormTextField 控件而不是 TextBox 控件会显示错误。 在这两种情况下,我的 ErrorSummary 控件在其集合中都有错误,因此我可以看到正在考虑该错误...

任何帮助都会受到赞赏。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕色琉璃 2024-07-27 12:50:52

您使用模板字段吗?

   <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> 

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> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文