迭代列表框silverlight的内容

时间:2011-01-20 14:01:11

标签: c# silverlight-3.0 listbox

我有一个列表框

 <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],但我似乎没有在运行时获取内容的值。

请帮助

1 个答案:

答案 0 :(得分:1)

<TextBlock Text="{Binding SelectedItem.Content, ElementName=QuestionsBox}" />