views:

106

answers:

1

Suppose I have a ListView and TextBox and they are located in different containers in the same Window.

Selecting items in the listview I want the TextBox Text property to be updated in accordance with the listview data bound selected item. Is it possible in XAML?

+2  A: 

Sure... Check this out

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
   <StackPanel>
    <ListBox x:Name="lb">
     <TextBlock Text="Hey"/>
     <TextBlock Text="There"/>
    </ListBox>
    <TextBlock Text="{Binding SelectedItem.Text, ElementName=lb}"/>
   </StackPanel>
</Page>

You can bind to SelectedItem. In this case, I'm cheating, because I know it's a TextBlock, but in the real world you'll have to write a DataTemplate (most likely).

Anvaka
Thank you, my problem was I couldn't set the ElementName, b/c VS issued error.
Dmitry