可以在鼠标悬停时更改按钮控件的图像源吗?
如果是怎么做的?
以下代码可能会有所帮助:
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
}
参考:
<!-- 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>