子オブジェクトの多対多およびバインドリストをサポートするようにDataFormを曲げようとしています。オブジェクトの表示を制御し、onchangeイベントにアクセスできるようになりました。
例えば:
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!";
}
}
変更を送信すると、この例では、CouponImageがドメインサービスのUpdateメソッドに送信されますが、クライアントはまだNULLです。
CustomerLoyaltyProgramOfferは、通知プロパティの変更を発生させないようです。
これは子オブジェクトの問題ですか?私はこれについてすべて間違っていますか?編集テンプレート全体を作成する必要がありますか?