【问题标题】:Silverlight, DataForm, AutoGeneratingField, RIA Services and Child EntitiesSilverlight、DataForm、AutoGeneratingField、RIA 服务和子实体
【发布时间】:2011-01-04 00:10:34
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

    您应该在 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-15
      • 1970-01-01
      • 2023-03-08
      • 2012-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-01
      相关资源
      最近更新 更多