我有2个模型在我的服务器端应用程序(商标&RetailStores)每个零售商店都有TradeMarkId字段用于交叉引用。在我的DomainService元数据模型上,我定义了RetailStore(TradeMarkId字段),如下所示:
Class RetailStore:
[Display(Order = 5, Name = "RetailStoreTradeMarkTitle", Description = "RetailStoreTradeMarkDescription", ResourceType = typeof(RegistrationDataResources))]
public int TradeMarkId { get; set; }
在客户端,我捕获AutoGeneratingField字段,并将其替换为一个列出所有商标的组合框,如下所示:
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 !我丢失了这个字段的验证。
所以我的问题是我做错了什么?是否有一种方法可以返回模型验证&;字段头??
提前感谢,子宫
我对这个很陌生,但我认为问题是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"。