Q: Wpf ListBox data binding to display TreeViewItem details I'm using WPF and have a TreeView on my form binding to model. Objects have attributes and I want to bind a selected item(in tree view) attributes to a listbox but I can't figure out how to this. My code is:
Bar class:
public class Bar
{
    string barName;
    List<bar> children;
    List<Foo> attrs;

    public string BarName
    {
        get { return barName; }
        set { barName = value; }
    }

    public List<Folder> Children
    {
        get { return children; }
        set { children = value; }
    }

    public List<Foo> Attributes
    {
        get { return attrs; }
        set { attrs = value; }
    }

    public Bar(string name)
    {
        barName = name;
        children = new List<Bar>();
        attrs = new List<Foo>();

        attrs.Add(new Foo { Name = "Attr1: " + name });
        attrs.Add(new Foo { Name = "Attr2: " + name });
        attrs.Add(new Foo { Name = "Attr3: " + name });
    }
}

Foo class:
public class Foo
{
    public string Name { get; set; }

}

Filling model:
        Bar bar = new Folder("bar1");
        bar.Children.Add(new Bar("bar1.1"));
        bar.Children[0].Children.Add(new Bar("bar1.1.1"));
        bar.Children.Add(new Bar("bar2"));

        this.DataContext = bar;

And also XAML:
<Window.Resources>
    <ResourceDictionary>
        <HierarchicalDataTemplate DataType="{x:Type local:Bar}"
                                      ItemsSource="{Binding Children}">
            <Grid Margin="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="16"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding BarName}"
                               Foreground="Black"
                               TextTrimming="CharacterEllipsis"
                               TextWrapping="Wrap"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Top"
                               Grid.Column="1"/>
            </Grid>
        </HierarchicalDataTemplate>
    </ResourceDictionary>
</Window.Resources>
<Grid>

    <TreeView Height="162" HorizontalAlignment="Left" Margin="203,0,0,0" Name="treeView1" VerticalAlignment="Top" Width="288" ItemsSource="{Binding Children}"/>
    <ListBox Height="100" HorizontalAlignment="Left" Margin="203,168,0,0" Name="listBox2" VerticalAlignment="Top" Width="288" ItemsSource="{Binding Name}"/>

</Grid>

Now TreeView binding works fine and I there is a Bar.Name displayed, but ListBox is empty. Please, explain me, what should I do?

A: You're binding your listbox to Name, so it's trying to find a property called "Name" in your Bar class. What I believe you're actually trying to do is show the attributes for the item that's currently selected in the TreeView. So bind to the TreeView's SelectedItem and set DisplayMemberPath to "Name":
    <ListBox Height="100" HorizontalAlignment="Left" Margin="203,168,0,0" Name="listBox2" VerticalAlignment="Top" Width="288" ItemsSource="{Binding SelectedItem.Attributes, ElementName=treeView1}" DisplayMemberPath="Name"/>

This will work, but a better idea would be to create a member in you Bar class for the currently selected item (e.g. "CurrentTreeItem") and bind both the treelist's SelectedItem and the ListBox's source items to that property, that way at least you can put breakpoints in the setter etc and make sure your front end controls are firing properly. The problem with doing this though is that you don't seem to be supporting IPropertyChange notification (if you don't know what that is then drop what you're doing and hit Google before going any further).

A: You can bind your listbox directly to TreeView selected item by changing xaml to 
 <TreeView Height="162" HorizontalAlignment="Left" Margin="203,0,0,0" Name="treeView1" VerticalAlignment="Top" Width="288" ItemsSource="{Binding Source}" />
 <ListBox DisplayMemberPath="Name" Height="100" HorizontalAlignment="Left" Margin="203,168,0,0" Name="listBox2" VerticalAlignment="Top" Width="288" ItemsSource="{Binding  Path=SelectedItem.Attributes, ElementName=treeView1}"/>

Sadly, tree view's selected item is read only property, so you can't easily create a property in you view and bind both listbox and treeview to it.
Also you should change your population to
 public ObservableCollection<Bar> Source { get; set; }
    public MainWindow()
    {
        InitializeComponent();
        Bar bar = new Bar("bar1");
        bar.Children.Add(new Bar("bar1.1"));
        bar.Children[0].Children.Add(new Bar("bar1.1.1"));
        bar.Children.Add(new Bar("bar2"));
        Source = new ObservableCollection<Bar>() { bar };
        this.DataContext = this;
    }

Be aware thought, that you have to implement INotifyPropertyChanged interface to allow bindings to update automatically
