假设我有一个ListView和TextBox,它们位于 在同一个窗口的不同容器中。
在列表视图中选择项目我希望更新TextBox Text属性 按照listview数据绑定所选项目。 在XAML中可以吗?
答案 0 :(得分:2)
当然......看看这个
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<ListBox x:Name="lb">
<TextBlock Text="Hey"/>
<TextBlock Text="There"/>
</ListBox>
<TextBlock Text="{Binding SelectedItem.Text, ElementName=lb}"/>
</StackPanel>
</Page>
您可以绑定到SelectedItem。在这种情况下,我在作弊,因为我知道它是一个TextBlock,但在现实世界中,你将不得不编写一个DataTemplate(最有可能)。