Play sound from navigation helper windows phone 8.1

时间:2016-04-04 18:12:58

标签: windows-phone-8.1

Would like to be able to play a sound from the navigation helper class (after back button handling). Can play from a page, but can't seem to figure the logic on playing from a class with no visual elements.

1 个答案:

答案 0 :(得分:0)

在用户按下按钮的页面中使用以下代码:

HardwareButtons.BackPressed += HardwareButtons_BackPressed;

在事件中进行检查并播放声音并制作

e.Handled=true; 

这会阻止后退导航(以防止在声音仍在播放时导航)

音频播放完毕后删除处理程序

HardwareButtons.BackPressed -= HardwareButtons_BackPressed;

并调用

Frame.GoBack();

希望有所帮助:)