Bind the value of a parameter in an ObjectDataProvider in WPF
I would like to be able to be doing this :
<ObjectDataProvider x:Key="dataProvider"
ObjectInstance="uiRoot:App.Current.Controller"
MethodName="GetMyViewModel">
<ObjectDataProvider.MethodPar开发者_运维知识库ameters>
<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? :(
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
精彩评论