我将XML文件中的项目添加到列表框中。当moues在listboxitem上时,我想在文本块中写出项目的描述。 这是我的XAML鳕鱼:
<ListBox x:Name="listBoxItemCollection" HorizontalAlignment="Left" Height="293" Margin="10,49,0,0" VerticalAlignment="Top" Width="165">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<EventSetter Event="MouseEnter" Handler="lbi_MouseEnter"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
C#代码:
private void lbi_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
ListBoxItem item = sender as ListBoxItem;
textBlockDescription.Text = item.Content.ToString();
}