views:

1060

answers:

1

I am trying to bend the DataForm to support many-to-many and bind lists of child objects. I've gotten as far as being able to control the display of the objects and have access to the on change event.

For example:

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

And here is my little override:

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;
        }

I'm grabbing the SelectedChanged event, and Updating the item, in my view model, that is set as the current item for the form as such:

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!";
        }
    }

When I submit the changes, in this example, CouponImage is sent to up the Update method in my domain service but Client is still NULL.

CustomerLoyaltyProgramOffer does not seem to raise a notify property change.

This this a child object problem? Am I going about this all wrong? Do HAVE to create an entire edit template?

A: 

You should set [Association] attribute on Client property of your CustomerLoyaltyProgramOffer class in your Model.designer.cs

Look at these two links for more info:

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

LILkillaBEE