Silverlight 4 - DataForm 上的 RIA 服务数据字段标头(自动生成字段)
我的服务器端应用程序上有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此很陌生,但我认为问题是 e.Field 位 - 您可能应该使用 e.Field.ReplaceTextBox。
我刚刚实现了一些非常相似的东西,这段代码对我有用:-
希望它对你有用! (请记住,您必须选择 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:-
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".