我有一个列表框
<ListBox Width="400" Height="150" x:Name="QuestionsBox" Margin="0,0,0,40">
<ListBoxItem Name="Item1" Content="Hello"></ListBoxItem>
<ListBoxItem Name="Item2" Content="Hello"></ListBoxItem>
</ListBox>
我想在选中时显示列表框中项目的内容。比如,如果用户选择Item1,那么我应该能够获得内容 - Hello
我尝试使用SelectedItem属性[QuestionsBox.SelectedItem]
,但我似乎没有在运行时获取内容的值。
请帮助
答案 0 :(得分:1)
<TextBlock Text="{Binding SelectedItem.Content, ElementName=QuestionsBox}" />