views:

23

answers:

1

I would like to be able to be doing this :

    <ObjectDataProvider x:Key="dataProvider"
                        ObjectInstance="uiRoot:App.Current.Controller" 
                        MethodName="GetMyViewModel">
        <ObjectDataProvider.MethodParameters>
            <system:Int32>{Binding Id}</system:Int32>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>

The emphasis being on

            <system:Int32>{Binding Id}</system:Int32>

I can't get around this. Any ideas? :(

+1  A: 

Bindings in WPF as you are trying to achieve can only be attached to DependencyProperties. The MethodParameters property is not a DependencyProperty, so binding to it will never work.

I'm under the impression that you want to get an ObjectDataProvider for each item within a list. Is that correct?

Are you trying to use the MVVM pattern? In that case create a VM structure in such way that a container ViewModel holds a list of child ViewModels, instead of trying to instantiate a VM trough an ObjectDataProvider. You can bind the list items to the child VM's without having to use an ObjectDataProvider for each item.

Conclusion is that you must not use an ObjectDataProvider for every element in the list.

Best regards,

Jan van de Pol

Jan van de Pol
You are correct in all the assumptions made in the answer :)
Andrei Rinea