views:

1753

answers:

2

Hi,

I want to add the selected item from the TreeView to the ListBox control using DataBinding (If it can work with Databinding).

 <TreeView HorizontalAlignment="Left" Margin="30,32,0,83" Name="treeView1" Width="133" >



      </TreeView>
      <ListBox  Margin="208,36,93,0" Name="listBox1" Height="196" VerticalAlignment="Top">       


      </ListBox>

TreeView is populated from the code behind page with some dummy data.

A: 

I'm pretty sure it is possible, since WPF is really flexible with data binding, but I haven't done that specific scenario yet.

I've been following a WPF Databinding FAQ from the MSDN blogs as of late and it provides a lot of insights that might help.

Dillie-O
+1  A: 

You can bind to an element using ElementName, so if you wanted to bind the selected tree item to the ItemsSource of a ListBox:

ItemsSource="{Binding SelectedItem, ElementName=treeView1}"
Dylan