如何在按钮鼠标中播放声音?

时间:2012-07-11 07:13:12

标签: wpf

  <Button Width="100" Height="50" Content="Click Me!">
           <Button.Style>
                <Style TargetType="{x:Type Button}">
                    <Style.Triggers>
                         <Trigger Property="IsMouseOver" Value="True">
                          < here i want to play sound but how?>
                         </Trigger>
                    </Style.Triggers>
              </Style>
         </Button.Style>
   </Button>

如果有人知道,请尝试但是没有找到任何事件,请帮助我

1 个答案:

答案 0 :(得分:0)

您可以轻松地将处理程序附加到MouseEnterMouseLeave事件:

<Button Width="100" Height="50" Content="Click Me!"
        MouseEnter="Button_MouseEnter" MouseLeave="Button_MouseLeave" /> 

private void Button_MouseEnter(object sender, MouseEventArgs e)
{
    // start playing
}

private void Button_MouseLeave(object sender, MouseEventArgs e)
{
    // stop playing
}