Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何实现调用按钮的计时器';WPF C#中的s事件?_C#_Wpf - Fatal编程技术网

如何实现调用按钮的计时器';WPF C#中的s事件?

如何实现调用按钮的计时器';WPF C#中的s事件?,c#,wpf,C#,Wpf,据我所知,Dispatcher的Tick事件需要使用EventArgs调用,而同一事件调用某些按钮的操作,这些按钮需要使用RoutedEventArgs调用。显然,我不能直接调用按钮的事件。我的问题是:有什么办法可以实现这一点吗 private void song_timer_Tick(object sender, EventArgs e) { if (playing == true) { lbl_curent_time.Text

据我所知,Dispatcher的Tick事件需要使用EventArgs调用,而同一事件调用某些按钮的操作,这些按钮需要使用RoutedEventArgs调用。显然,我不能直接调用按钮的事件。我的问题是:有什么办法可以实现这一点吗

private void song_timer_Tick(object sender, EventArgs e)
    {
        if (playing == true)
        {
            lbl_curent_time.Text = audio_device.audioFileReader.CurrentTime.ToString();

            if (music_state_progress.Value < music_state_progress.Maximum)
            {
                music_state_progress.Value = music_state_progress.Value + 1;
                taskbar.SetProgressValue(Convert.ToInt32(music_state_progress.Value), Convert.ToInt32(music_state_progress.Maximum));
            }

            if (lbl_curent_time.Text == audio_device.audioFileReader.TotalTime.ToString())
                if (music_list.SelectedIndex < music_list.Items.Count - 1)
                {
                    btn_next_Click(sender, e);
                    music_list_DoubleClick(sender, e);
                }
                else if (repeat_checkbox.IsChecked == true)
                {
                    music_list.SelectedIndex = 0;
                    music_list_DoubleClick(sender, e);
                }
                else
                {
                    btn_stop_Click(sender, e);
                    lbl_curent_time.Text = "00:00:00.0000000";
                    lbl_max_time.Text = "00:00:00.0000000";
                }
        }
    }
private void song\u timer\u Tick(对象发送方,事件参数e)
{
如果(播放==真)
{
lbl_current_time.Text=audio_device.audioFileReader.CurrentTime.ToString();
if(音乐状态进度值<音乐状态进度最大值)
{
music_state_progress.Value=music_state_progress.Value+1;
SetProgressValue(Convert.ToInt32(music_state_progress.Value),Convert.ToInt32(music_state_progress.max));
}
if(lbl\u curent\u time.Text==audio\u device.audioFileReader.TotalTime.ToString())
if(music\u list.SelectedIndex
取自

替换:

btn_stop_Click(sender, e);
与:


您是否在按钮单击处理程序中使用
EventArgs
?不,是RoutedEventArgs,这是WPF所要求的。然后,我建议将代码提取到某个公共位置,并从按钮单击处理程序和勾号处理程序调用该方法。那你就不用担心了。
btn_stop_Click(sender, e);
btn_stop.RaiseEvent(new RoutedEventArgs(System.Windows.Controls.Primitives.ButtonBase.ClickEvent));