[英]Listbox onmouseover event to change a textblock text
I want to change a textblock text thanks to a mouseover event on a listbox. 我要更改文本块文本,这要归功于列表框上的mouseover事件。 The main issue is that I can't find out how to add a mouseover event on a listbox. 主要问题是我找不到如何在列表框上添加鼠标悬停事件。 I found a way to select a listbox item on a mouseover event, but I don't want it to select. 我找到了一种在鼠标悬停事件上选择列表框项目的方法,但我不希望它被选择。 I did it this way, thanks to this post 我这样做了,多亏了这篇文章
<ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="IsSelected" Value="True"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
Try this: 尝试这个:
<ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<EventSetter Event="MouseEnter" Handler="ListBoxItem_MouseEnter"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
private void ListBoxItem_MouseEnter(object sender, MouseEventArgs e)
{
(sender as ListBoxItem).Content = "Your text";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.