1

可以在鼠标悬停时更改按钮控件的图像源吗?

如果是怎么做的?

4

2 回答 2

4

以下代码可能会有所帮助:

button1.MouseEnter += new MouseEventHandler(button1_MouseEnter);
button1.MouseLeave += new MouseEventHandler(button1_MouseLeave);

void button1_MouseEnter(object sender, MouseEventArgs e)
{
    button1.Content = image1;
    //do something
}

void button1_MouseLeave(object sender, MouseEventArgs e)
{
    //do something
}
于 2012-05-29T09:06:33.277 回答
3

您可以为此使用触发器。您可以按照本文本文寻求解决方案

参考:

<!-- Button will change from Blue to Yellow on MouseOver -->
<Style TargetType="{x:Type Button}">
    <Setter Property="Background" Value="Blue" />
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Yellow" />
        </Trigger>
    </Style.Triggers>
</Style>
于 2012-05-29T09:08:27.383 回答