2010-01-12 103 views
0

我試圖彎曲DataForm以支持多對多和綁定子對象列表。我已經儘可能地控制對象的顯示並可以訪問on change事件。Silverlight,DataForm,AutoGeneratingField,RIA服務和子實體

例如:

OfferEditorForm.AutoGeneratingField += new EventHandler<DataFormAutoGeneratingFieldEventArgs>(OfferEditorFormGeneratingField); 

這裏是我的小覆蓋:

if (e.PropertyName == "Client") 
     { 
      var stack = new StackPanel(); 
      var dataField = new DataField { Content = stack, Label = "Client:" }; 
      var binding = new Binding("CustomerClients") { Source = _viewModel }; 
      var combo = new ComboBox 
      { 
       DisplayMemberPath = "Name", 
       Name = "OfferEditForm_Client", 
       SelectedItem = _viewModel.CustomerLoyaltyProgramOffer.Client 
      }; 

      combo.SetBinding(ComboBox.ItemsSourceProperty, binding); 
      combo.SelectionChanged += new SelectionChangedEventHandler(CustomerClients_SelectionChanged); 
      stack.Children.Add(combo); 
      dataField.Content.UpdateLayout(); 
      e.Field = dataField; 
     } 

我抓住了SelectedChanged事件,並更新項目,在我看來模式,即設定爲當前項目的形式如下:

void CustomerClients_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
     FrameworkElement frameworkElement = sender as FrameworkElement; 
     ComboBox comboBox = (ComboBox)frameworkElement.FindName("OfferEditForm_Client"); 
     if (comboBox != null) 
     { 
      _viewModel.CustomerLoyaltyProgramOffer.Client = (CustomerClient)comboBox.SelectedItem; 
      _viewModel.CustomerLoyaltyProgramOffer.CouponImage = "OMG!"; 
     } 
    } 

當我提交更改時,在本例中,Coup onImage發送到我的域服務中的Update方法,但Client仍爲NULL。

CustomerLoyaltyProgramOffer似乎沒有引發通知屬性更改。

這是一個小孩對象問題嗎?我是否全部錯了?是否必須創建一個完整的編輯模板?

回答