Silverlight MouseOver

时间:2012-05-29 08:44:48

标签: silverlight silverlight-4.0

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

如果它是如何完成的?

2 个答案:

答案 0 :(得分: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
}

答案 1 :(得分:3)

您可以使用Trigger。您可以按照thisthis条款了解解决方案

REF:

<!-- 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>