0

I've just started to learn binding in WPF and am having some trouble with using multiple ObjectDataProviders with the same control.

I have two ObjectDataProviders :

  1. Is used to get a list of customer locations from a database and is used to populate a TreeView and
  2. Takes a location as a parameter and returns all the customers from that location, populating a listView.

I'd like to make it so that when I click on one of the TreeView items, that it would take the SelectedItem text as the parameter, use it to populate the listview.

    <ObjectDataProvider 
        x:Key="getLocations" 
        ObjectType="{x:Type local:DataSetCreator}"
        MethodName="getLocations" 
        />

    <ObjectDataProvider 
        x:Key="getCustomersFromLocation" 
        ObjectType="{x:Type local:DataSetCreator}"
        MethodName="getCustomersFromLocation">
        <ObjectDataProvider.MethodParameters>
            <x:Static Member="System:String.Empty" />
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>


    <TreeView HorizontalAlignment="Left" 
        Margin="12,12,0,12" 
        Name="treeView2" Width="186"      
        ItemsSource="{Binding Source={StaticResource getLocations}}" >

        <TreeView.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Country}" />                    
            </DataTemplate>
        </TreeView.ItemTemplate>
    </TreeView>


    <ListView x:Name="lstCustomers"
            ItemsSource="{Binding Source={StaticResource getCustomersFromLocation}}" Margin="204,41,12,12">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="CustomerID"
                        Width="200"
                        DisplayMemberBinding="{Binding Path=CustomerID}" />
                <GridViewColumn Header="Company Name"
                        Width="370"
                        DisplayMemberBinding="{Binding Path=CompanyName}" />
            </GridView>
        </ListView.View>
    </ListView>

Is it possible to achieve this within the XAML, or do I need to use the code-behind?

H.B.
  • 166,899
  • 29
  • 327
  • 400
RegisteredUser
  • 206
  • 1
  • 4

1 Answers1

0

ObjectDataProviders are not very flexible as they cannot be bound. Among other things you could bind to the SelectedItem of the TreeView and employ a Binding.Converter to get you the items right items based on that value.

H.B.
  • 166,899
  • 29
  • 327
  • 400