2012-07-13 86 views
3

我剛開始學習WPFand MVVM.Here的選擇項更新文本框是我想做的事:TreeView控件(MVVM):從樹

使用時選擇樹中的任何節點,該節點的描述顯示在文本框。 這裏是XMAL(這是在爲組合框不是樹狀)

 <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> 
+0

什麼是CurrentItem?屬性在ViewModel ..... – ethicallogics 2012-07-13 04:51:15

+0

@ethicallogics正如我所說,我從複選框的一些例子複製片段。說明是屬性。 Text =「{Binding Path = Description}」 但是,當我選擇nodes.it時保持不變。所以我希望它改變,當我選擇其他節點 – Satbir 2012-07-13 04:59:01

回答

5

嘗試這種方式

<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確實有只讀SelectedItem屬性。我希望這將有助於。

+0

非常感謝你和社區。 – Satbir 2012-07-13 05:09:36