views:

441

answers:

0

I'm having some trouble with setting up an ObjectDataProvider with custom method parameters.

For a start I have a ListBox which is bound to a custom List which is set up programmatically with ItemsSource property. Then i would like to SelectedItem to be a parameter to my custom method. So in XAML i have:

<ListBox /*omitted*/ SelectionMode="Single">
        <ListBox.SelectedItem>
                <Binding Source="{StaticResource getHostByPortProvider}" Path="MethodParameters[0]" BindsDirectlyToSource="True" />
        </ListBox.SelectedItem>

Next, result of this method call is ment to be an ItemsSource for a ListView:

 <ListView ItemsSource="{Binding Source={StaticResource getHostByPortProvider}}" >

ObjectDataProvider is configured to use ObjectInstance, which is set in code behind.

Here is XAML:

<ObjectDataProvider MethodName="GetHostByPortType" x:Key="getHostByPortProvider">
        <ObjectDataProvider.MethodParameters>
            <cad:Port></cad:Port>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>

and the code:

ObjectDataProvider odr = this.TryFindResource("getHostByPortProvider") as ObjectDataProvider;

            if (odr != null)
                odr.ObjectInstance = sr;

As a result the method is not called when I change selection in ListBox and so here is no change in UI, the ListView is not filled with expected content, so I assume I missed something. What I did wrong?