La clase SystemSounds
proporciona algunos sonidos del sistema, tienen un método Play()
. Para usar esto en XAML tendrías que recurrir a algunos hacks extraños, implementar mucha lógica personalizada o usar Blend Interactivity para definir tu propia TriggerAction que puede usar un SystemSound
y reproducirlo. Método
La interactividad:
public class SystemSoundPlayerAction : System.Windows.Interactivity.TriggerAction<Button>
{
public static readonly DependencyProperty SystemSoundProperty =
DependencyProperty.Register("SystemSound", typeof(SystemSound), typeof(SystemSoundPlayerAction), new UIPropertyMetadata(null));
public SystemSound SystemSound
{
get { return (SystemSound)GetValue(SystemSoundProperty); }
set { SetValue(SystemSoundProperty, value); }
}
protected override void Invoke(object parameter)
{
if (SystemSound == null) throw new Exception("No system sound was specified");
SystemSound.Play();
}
}
<Window
xmlns:sysmedia="clr-namespace:System.Media;assembly=System"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">
...
<Button Content="Test2">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:EventTrigger.Actions>
<local:SystemSoundPlayerAction SystemSound="{x:Static sysmedia:SystemSounds.Beep}"/>
</i:EventTrigger.Actions>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
(. no sé si SystemSounds.Beep
es el que usted está buscando)
Nota de David Veeneman:
Para otros r esearching esta cuestión, la mezcla interactividad se hace referencia en la respuesta requiere una referencia a System.Windows.Interactivity.dll, que se encuentra en C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.0\Libraries\
¡Respuesta agradable! Aceptado y +1. –
Gracias; de hecho, aprendí algo al responder esto :) –
Para otros que investigan este problema, la interactividad de mezcla a la que se hace referencia en la respuesta requiere una referencia a System.Windows.Interactivity.dll, que se encuentra en C: \ Archivos de programa (x86) \ Microsoft SDKs \ Expression \ Blend \ .NETFramework \ v4.0 \ Libraries \ –