Silverlight 4 - DataForm 上的 RIA 服务数据字段标头(自动生成字段)

发布于 2024-12-21 06:23:31 字数 1429 浏览 3 评论 0原文

我的服务器端应用程序上有 2 个模型(商标和零售商店) 每个 RetailStore 都有 TradeMarkId 字段以供交叉引用。 在我的 DomainService 元数据模型上,我定义了 RetailStore(TradeMarkId 字段),如下所示:

Class RetailStore:
[Display(Order = 5, Name = "RetailStoreTradeMarkTitle", Description = "RetailStoreTradeMarkDescription", ResourceType = typeof(RegistrationDataResources))]
public int TradeMarkId { get; set; }

在客户端,我捕获了 AutoGenerateField 该字段,并将其替换为列出所有商标的组合框,如下所示:

        if (e.PropertyName == "TradeMarkId")
        {

            ComboBox TradeMarkIdComboBox = new ComboBox { DisplayMemberPath = "TradeMarkName" };
            Binding itemsSource = new Binding("TradeMarks") { Source = this.retailStoreDomainDataSource.DomainContext };
            Binding selectedItem = new Binding("TradeMark") { Mode = BindingMode.TwoWay };
            TradeMarkIdComboBox.SetBinding(ComboBox.ItemsSourceProperty, itemsSource);
            TradeMarkIdComboBox.SetBinding(ComboBox.SelectedItemProperty, selectedItem);

            DataField TradeMarkIdField = new DataField
            {
                Content = TradeMarkIdComboBox,
                Label = e.Field.Label

            };
            e.Field = TradeMarkIdField;

        }

在绑定方面,一切都完美运行,但我丢失了我在模型中定义的“RetailStoreTradeMarkTitle”,Description =“RetailStoreTradeMarkDescription”DisplayAttributes!我失去了该字段的验证。

所以我的问题是我做错了什么?有没有办法取回模型验证&字段标题??

提前致谢, 瓦梅

I have 2 models on my server side app ( TradeMarks & RetailStores )
each RetailStore have the TradeMarkId field for cross referencing.
On my DomainService metadata model I defined the RetailStore(TradeMarkId field) as follows:

Class RetailStore:
[Display(Order = 5, Name = "RetailStoreTradeMarkTitle", Description = "RetailStoreTradeMarkDescription", ResourceType = typeof(RegistrationDataResources))]
public int TradeMarkId { get; set; }

On the client side I catch on the AutoGeneratingField the field and replace it by a combobox listing all the TradeMarks as follows:

        if (e.PropertyName == "TradeMarkId")
        {

            ComboBox TradeMarkIdComboBox = new ComboBox { DisplayMemberPath = "TradeMarkName" };
            Binding itemsSource = new Binding("TradeMarks") { Source = this.retailStoreDomainDataSource.DomainContext };
            Binding selectedItem = new Binding("TradeMark") { Mode = BindingMode.TwoWay };
            TradeMarkIdComboBox.SetBinding(ComboBox.ItemsSourceProperty, itemsSource);
            TradeMarkIdComboBox.SetBinding(ComboBox.SelectedItemProperty, selectedItem);

            DataField TradeMarkIdField = new DataField
            {
                Content = TradeMarkIdComboBox,
                Label = e.Field.Label

            };
            e.Field = TradeMarkIdField;

        }

everything works perfectly in term of binding but I lost the "RetailStoreTradeMarkTitle", Description = "RetailStoreTradeMarkDescription" DisplayAttributes that I defined in the model! and I lost the Validation for this field.

So my question what am I doing wrong ? is there a way to get back the model validation & field headers ??

Thnaks in advance,
WaMe

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

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

发布评论

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

评论(1

红焚 2024-12-28 06:23:31

我对此很陌生,但我认为问题是 e.Field 位 - 您可能应该使用 e.Field.ReplaceTextBox。

我刚刚实现了一些非常相似的东西,这段代码对我有用:-

       if (e.PropertyName == "TradeMarkId")
       {
           ComboBox target = new ComboBox() { DisplayMemberPath = "TradeMarkName", SelectedValuePath = "TradeMarkId" };
           target.ItemsSource = TaskManager.Manager.GanttItemSource;
           e.Field.ReplaceTextBox(target, ComboBox.SelectedValueProperty, binding => binding.Converter = new TargetNullValueConverter());             
       }

希望它对你有用! (请记住,您必须选择 ID 属性 - 我不确定您使用哪个字段作为商标 ID - 我猜它是“TradeMarkId”。

I'm pretty new to this, but I think the problem is the e.Field bit - you should probably be using e.Field.ReplaceTextBox.

I have just implemented something very similar and this code worked for me:-

       if (e.PropertyName == "TradeMarkId")
       {
           ComboBox target = new ComboBox() { DisplayMemberPath = "TradeMarkName", SelectedValuePath = "TradeMarkId" };
           target.ItemsSource = TaskManager.Manager.GanttItemSource;
           e.Field.ReplaceTextBox(target, ComboBox.SelectedValueProperty, binding => binding.Converter = new TargetNullValueConverter());             
       }

Hope it works for you! (Bare in mind you will have to select the ID property - I'm not sure which field you are using as the trade mark id - I have guessed it's "TradeMarkId".

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