Satbir
Satbir

Reputation: 6506

TreeView (MVVM ) : Update Text Box from selected Item of tree

I just started learning WPFand MVVM.Here is what i want to do:

When use select any node from tree , Description of that node is displayed in text box. Here is XMAL( which was working for combobox not for treeview)

      <Grid Margin="0,0,0,33" Name="grid1">
        <TreeView   HorizontalAlignment="Left" 
            Margin="24,47,0,6" 
            Name="treeView1" 
            Width="120"
            ItemsSource="{Binding Path=.}">        

            </TreeView>
        <TextBox
            Margin="150,47,24,61" 
            Name="textBox1"
            Text="{Binding Path=CurrentItem.Description}"
                 />
    </Grid>

Upvotes: 3

Views: 2276

Answers (1)

yo chauhan
yo chauhan

Reputation: 12295

Try it this way

<TreeView   HorizontalAlignment="Left" x:Name="treeView1"
        Margin="24,47,0,6" 
        Width="120"
        ItemsSource="{Binding Path=.}"   >
        <TreeViewItem></TreeViewItem>
    </TreeView>
    <TextBox
        Margin="150,47,24,61" 
        Name="textBox1"
        Text="{Binding Path=SelectedItem.Description, ElementName=treeview1}"
             />

TreeView do have readonly SelectedItem property .I hope this will help.

Upvotes: 5

Related Questions