Search code examples
wpfvb.netxamlbindingancestor

wpf binding text to parent listbox's contents


I have a listBox whose items are to be shown in a textbox format, like so:-

   <ListBox ItemsSource="{Binding movieList}" Name="innerList">
      <ListBox.ItemTemplate >
         <DataTemplate >
            <TextBox Text="-------" TextChanged="TextBox_TextChanged_1"/>
         </DataTemplate>
       </ListBox.ItemTemplate>
   </ListBox> 

EDIT:

Sorry, movie list was an observablecollection (of Movie) instead of being (of String)

How do I get the textbox to show the contents of its ancestor (the innerList) ?


Solution

  • If you want to display the title of a movie in the TextBox, just use that:

    <TextBox Text="{Binding Title}" TextChanged="TextBox_TextChanged_1"/>
    

    (assuming the items in the list are objects with a Title property)