0
votes

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

1

1 Answers

0
votes

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