2015-08-15 67 views
0

我有listBox,我想看到选定的项目在某些文本框上的列表框。如何绑定ListBox所选项目和TextBox?

(集合为字符串列表)

我尝试写的代码,但是这是行不通的。

<ListBox x:Name="Collection__" Grid.Row="0" ItemsSource="{Binding Collection}" /> 

    <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Vertical" Margin="5"> 
     <DockPanel> 
      <TextBlock DockPanel.Dock="Left" Text="Collection name:"/> 
      <TextBox DockPanel.Dock="Left" Margin="5,0" Text="{Binding ElementName=Collection__, Path=SelectedItem}"/> 
     </DockPanel> 
    </StackPanel> 

回答

0

发现...

<StackPanel> 
    <ListBox x:Name="ElementListBox" ItemsSource="{Binding Elements}" 
      IsSynchronizedWithCurrentItem="True"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel Orientation="Vertical"> 
        <TextBlock Text="{Binding Name}"/> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
    <TextBox Text="{Binding Elements/Name}"/> 
</StackPanel> 
相关问题