0

我正在尝试弯曲 DataForm 以支持多对多和绑定子对象列表。我已经能够控制对象的显示并可以访问 on change 事件。

例如:

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 方法,但 Client 仍然为 NULL。

CustomerLoyaltyProgramOffer 似乎没有引发通知属性更改。

这是一个子对象问题吗?我对这一切都错了吗?必须创建一个完整的编辑模板吗?

4

1 回答 1

0

您应该在 Model.designer.cs 中的 CustomerLoyaltyProgramOffer 类的 Client 属性上设置 [Association] 属性

查看这两个链接以获取更多信息:

http://tech.rofas.net/post/Working-with-associated-POCO-objects-in-WCF-RIA-Services.aspx http://blogs.msdn.com/digital_ruminations/archive/2009/11/18 /composition-support-in-ria-services.aspx

于 2010-02-02T20:26:26.520 回答