将验证弹出窗口添加到 Silverlight Dataform 上的自定义组合框字段

发布于 2024-08-29 03:18:17 字数 1036 浏览 1 评论 0原文

我正在使用绑定到我的视图模型上的实体的数据表单,对于一个字段,我需要创建一个项目组合框,我创建它并在自动生成事件上使用此代码绑定它:

            ComboBox makes = new ComboBox();
              Binding selectedItem = new Binding("conc_claimtype")
            {  
                ValidatesOnExceptions = true,
                ValidatesOnDataErrors = true,
                 ValidatesOnNotifyDataErrors = true,
                NotifyOnValidationError= true,
                Mode = BindingMode.TwoWay
            };
            makes.Items.Add("AI");
            makes.Items.Add("CO");
            makes.Items.Add("RE");

            makes.SetBinding(ComboBox.SelectedItemProperty, selectedItem);
            DataField makesField = new DataField {  Content = makes, Label = e.Field.Label };
            e.Field = makesField;
            e.Cancel = false;

我试图弄清楚我如何当该字段为必填字段时,可以使弹出窗口出现在组合框中,并像常规文本框一样显示错误消息,如果您将其设置为必填且未选择,则会给出验证错误,因为我可以在 ValidationSummary 上看到它,但它不显示显示标签,只显示错误消息,我认为这可能是一个错误。

我真正需要的是显示该字段是像文本框这样的弹出窗口所必需的,我想我必须为组合框提供某种样式来显示验证错误,对吗?我在哪里可以找到这个样式?

I m using a Dataform that is binded to a entity on my view model, for one field i need to create a combobox of items , i create it and bind it ok using this code on the autogenerating event:

            ComboBox makes = new ComboBox();
              Binding selectedItem = new Binding("conc_claimtype")
            {  
                ValidatesOnExceptions = true,
                ValidatesOnDataErrors = true,
                 ValidatesOnNotifyDataErrors = true,
                NotifyOnValidationError= true,
                Mode = BindingMode.TwoWay
            };
            makes.Items.Add("AI");
            makes.Items.Add("CO");
            makes.Items.Add("RE");

            makes.SetBinding(ComboBox.SelectedItemProperty, selectedItem);
            DataField makesField = new DataField {  Content = makes, Label = e.Field.Label };
            e.Field = makesField;
            e.Cancel = false;

I m trying to figure how i can make the popup appear in the combobox when the field is required and show the error message as the regular textbox does, if u set it to required and didn't select, it gives the validation error because i can see it on the ValidationSummary, but it dosen't schow the display label, only the error message, i think it maybe a bug with it.

what i really need it's to show that field is required with that popup like the textbox, i think i have to get some kind of style to the combobox to show validation erros right? where can i find this syle?

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

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

发布评论

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

评论(1

随梦而飞# 2024-09-05 03:18:17

我解决了这个问题,做了一个小黑客,我在域上下文的元数据上添加了一条验证规则,其中我说值不能是空字符串,然后我向组合框中的绑定添加一个转换器,当它为空时我转换回空字符串,这样我就可以进行验证工作并弹出窗口,并在组合框中显示错误消息。

如果有人需要解决这个问题,我可以在这里发布一些代码。

我在 stackoverflow 上的第一个问题,我自己回答;)哈哈

I solved it making a small hack , i add a validation rule on the metadata of the domaincontext where i said the value coulnd't be a empty string, then i add a converter to the binding in the combobox, and when it is null i convertback to a emptystring and that way i got the validation working adn popup with the error message apear on the combobox.

I can post some code here if anyone needs to solve this issue.

My first question on stackoverflow, and i answer it myself ;) lol

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