Silverlight,DataForm,AutoGeneratingField,RIA Services和Child Entities

时间:2010-01-12 01:50:45

标签: silverlight wcf-ria-services silverlight-toolkit

我正在尝试弯曲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似乎没有引发通知属性更改。

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

1 个答案:

答案 0 :(得分: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