tags:

views:

22

answers:

1

I want to create a listbox that'll be bound to XPath, relative to the other listbox's currently selected item.

It's using XmlDataProvider for the data, and the XML file looks like this:

<Programs>
    <Program name="...">
        <Step name="..."/>
        <Step name="..."/>
    </Program>
    <Program name="another">

    ...

</Programs

So, the "parent" listbox is listing out all the programs, while "child" shows only Steps from the current Program. I just need a pointer on the fact what's such type of binding called.

Thanks in advance.

+1  A: 

Here you go. Hope this answers your question.

<Window x:Class="StackOverflow.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:StackOverflow"
        xmlns:uc="clr-namespace:StackOverflow.UserControls"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <XmlDataProvider x:Key="xml">
            <x:XData>
                <Programs xmlns="">
                    <Program name="Program">
                        <Step name="Step1"/>
                        <Step name="Step2"/>
                    </Program>
                    <Program name="Program2">
                        <Step name="Step3"/>
                        <Step name="Step4"/>
                    </Program>
                </Programs>
            </x:XData>
        </XmlDataProvider>
    </Window.Resources>

    <Grid>
        <StackPanel>
            <ListBox x:Name="parent" ItemsSource="{Binding Source={StaticResource xml}, XPath=Programs/Program}" 
                     Height="100">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding XPath=@name}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <ListBox DataContext="{Binding ElementName=parent, Path=SelectedItem}" ItemsSource="{Binding XPath=Step}" 
                     Height="100">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding XPath=@name}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>

    </Grid>
</Window>
karmicpuppet
Sorry it took me a while to answer, I wasn't near computer for a while. Thanks, that clears some things out!
Johnny