私は最近C#の作業を開始しましたが、非常にアマチュアです。以下で説明する問題のヘルプがあれば、私にとって非常に役立ちます。
私がやりたかったのは、イベントハンドラーのvideo_panelにもアクセスできることですが、今のところ、メディア要素をグローバルに宣言してその値をvideo_panelに設定しようとしましたが、それでも何をすべきかわかりません。メッセージを表示する代わりに、現在再生中のビデオを一時停止します
namespace Play_pause
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
static int index = 0;
static System.Timers.Timer aTimer = new System.Timers.Timer();
public MainWindow()
{
InitializeComponent();
video_panel.Play();
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000;
aTimer.Start();
}
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
index++;
if (index %2==0)
{
MessageBox.Show("Can't access media element in the event handler/n how to
set it global?");
}
}
}
}