Export (0) Print
Expand All
2 out of 3 rated this helpful - Rate this topic

SoundPlayerAction Class

Represents a light weight audio playback TriggerAction used to play .wav files.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[RuntimeNamePropertyAttribute("Name")] 
public class SoundPlayerAction : TriggerAction
/** @attribute RuntimeNamePropertyAttribute("Name") */ 
public class SoundPlayerAction extends TriggerAction
RuntimeNamePropertyAttribute("Name") 
public class SoundPlayerAction extends TriggerAction
<SoundPlayerAction .../>

The following example shows how use the SoundPlayerAction to trigger audio playback of a .wav file using an EventTrigger on the Click and MouseEnter events.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <Page.Triggers>
    <EventTrigger RoutedEvent="Button.Click" SourceName="clickButton">
      <EventTrigger.Actions>
        <SoundPlayerAction Source="media\lowbat.wav"/>
      </EventTrigger.Actions>
    </EventTrigger>
    <EventTrigger RoutedEvent="Button.MouseEnter" SourceName="hoverButton">
      <EventTrigger.Actions>
        <SoundPlayerAction Source="media\tada.wav"/>
      </EventTrigger.Actions>
    </EventTrigger>
  </Page.Triggers>

  <StackPanel Width="200">
    <Button Name="clickButton">Click to Play Sound</Button>
    <Button Name="hoverButton">Hover to Play Sound</Button>
  </StackPanel>
</Page>

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <Page.Triggers>
    <EventTrigger RoutedEvent="Button.Click" SourceName="clickButton">
      <EventTrigger.Actions>
        <SoundPlayerAction Source="media\lowbat.wav"/>
      </EventTrigger.Actions>
    </EventTrigger>
    <EventTrigger RoutedEvent="Button.MouseEnter" SourceName="hoverButton">
      <EventTrigger.Actions>
        <SoundPlayerAction Source="media\tada.wav"/>
      </EventTrigger.Actions>
    </EventTrigger>
  </Page.Triggers>

  <StackPanel Width="200">
    <Button Name="clickButton">Click to Play Sound</Button>
    <Button Name="hoverButton">Hover to Play Sound</Button>
  </StackPanel>
</Page>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.