每当我在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.

07-24 12:37