伙计们,我正在 WPF 应用程序(C#)的媒体元素中播放视频文件。
我现在需要放置一个上下文菜单(即,当您右键单击时,您可能会获得播放/暂停/停止视频的选项)。我做了以上
ContextMenu contextMenu1 = new ContextMenu();
MenuItem vidPlay = new MenuItem() { Header = "Play" }; vidPlay.Click += new System.Windows.RoutedEventHandler(PlayVid_Click);
MenuItem vidPause = new MenuItem() { Header = "Pause" }; vidPlay.Click += new System.Windows.RoutedEventHandler(PauseVid_Click);
MenuItem vidStop = new MenuItem() { Header = "Stop" }; vidPlay.Click += new System.Windows.RoutedEventHandler(StopVid_Click);
并使其在“网格”上可用
//video play pause
contextMenu1.Items.Add(vidPlay); contextMenu1.Items.Add(vidPause); contextMenu1.Items.Add(vidStop);
单击这些子程序时的子程序如下
//play pause routine handlers
//'me' is the media element,s name
void PlayVid_Click(object sender, EventArgs e)
{
me.Play();
}
void PauseVid_Click(object sender, EventArgs e)
{
me.Pause();
}
void StopVid_Click(object sender, EventArgs e)
{
me.Stop();
}
但是,当单击任何上下文菜单项时,视频不会暂停或停止。
我哪里做错了 ?