Silverlight中 ListBox的取值问题?
怎么取到ListBox显示的text,而不是value?
啥意思?
C# codelstTemp.SelectedItem.ToString();
You need first init a new instance of ListBoxItem in the code behind.
You can try the sample code below.
-------------------------------------------------------------------------
xaml:
<ListBox x:Name="lstBox" SelectionChanged="lstBox_SelectionChanged">
<ListBoxItem Content="hello"> </ListBoxItem>
<ListBoxItem Content="world"> </ListBoxItem>
</ListBox>
<TextBlock x:Name="txt"> </TextBlock>
C#:
void lstBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBoxItem item = new ListBoxItem();
item = (ListBoxItem)lstBox.SelectedItem;
txt.Text = item.Content.ToString();
}
-------------------------------------------------------------------------
Hope it helps.