【问题标题】:Listbox onmouseover event to change a textblock text用于更改文本块文本的列表框 onmouseover 事件
【发布时间】:2014-09-05 06:52:14
【问题描述】:

由于列表框上的鼠标悬停事件,我想更改文本块文本。 主要问题是我不知道如何在列表框上添加鼠标悬停事件。 我找到了一种在鼠标悬停事件上选择列表框项目的方法,但我不希望它选择。 我是这样做的,感谢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>

【问题讨论】:

  • 文本块在哪里?在 ItemTemplate 还是其他地方?
  • 它在包含列表框的用户控件之外,所以我会尝试调用@Tzah Mama 给出的样式

标签: c# wpf xaml listbox mouseover


【解决方案1】:

试试这个:

<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";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-26
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-12-31
    • 2011-09-30
    相关资源
    最近更新 更多