c# - 向WPF Surface应用程序添加声音效果

标签 c# wpf audio pixelsense

每当我在WPF Surface应用程序中触摸/移动对象时,我都试图播放声音,以描述该对象已被选中或其移动。这是我尝试过的方法,但似乎不起作用。

SoundPlayerAction soundPlayerAction = new SoundPlayerAction();
soundPlayerAction.Source = new Uri(@"C:\Resources\Selection.wav", UriKind.RelativeOrAbsolute);
EventTrigger eventTrigger = new EventTrigger(TouchEnterEvent); // this is the event you want to trigger the sound effect.
eventTrigger.Actions.Add(soundPlayerAction);

任何反馈或想法将不胜感激。

最佳答案

在您的项目中创建一个新文件夹,并将其重命名为SOUNDS,然后在其中插入声音文件,然后尝试以下操作:

  SoundPlayerAction soundPlayerAction = new SoundPlayerAction();
    soundPlayerAction.Source = new Uri(@"SOUNDS\Selection.wav", UriKind.RelativeOrAbsolute);


    EventTrigger eventTrigger = new EventTrigger(TouchEnterEvent); // this is the event you want to trigger the sound effect.

    eventTrigger.Actions.Add(soundPlayerAction);
     Triggers.Add(eventTrigger); // Add this event trigger to Window.Triggers collection.

关于c# - 向WPF Surface应用程序添加声音效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31780635/

相关文章:

audio - 具有处理和音频输入的NullPointerException

C# - 将 json 格式的数据解析为嵌套的哈希表

c# - 为什么 GetEntryAssembly 返回 null?

c# - 无法在列表框中绑定(bind)命令

Windows shell : How can I get the audio device(s) name(s)?

python - 我可以在 Windows 上监控系统音频并进行分析吗?

c# - 在集合中查找日期最近的项目

c# - 未找到时区异常

wpf - 如何在我的 wpf 应用程序中实现 ajax 样式的加载面板?

wpf - 如何选择 WPF 的图标作为应用程序的图标?