0

As I understand, the DispatcherTimer's Tick event needs to be called with EventArgs, whereas the same event calls the action of some buttons, which need to be called with RoutedEventArgs. Obviously, I cannot call the buttons' events directly. My question is: is there any way to implement this, by all means?

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";
                }
        }
    }
3
  • Are you using EventArgs in button click handler? Commented Jul 26, 2014 at 15:27
  • Nope, RoutedEventArgs, as it is required by WPF. Commented Jul 26, 2014 at 15:30
  • I would then suggest to extract out the code to some common place and call that method from button click handler and from your tick handler. You don't have to worry about it then. Commented Jul 26, 2014 at 15:42

2 Answers 2

1

Replace:

btn_stop_Click(sender, e);

with:

btn_stop.RaiseEvent(new RoutedEventArgs(System.Windows.Controls.Primitives.ButtonBase.ClickEvent));
Sign up to request clarification or add additional context in comments.

Comments

1
ButtonAutomationPeer peer =
  new ButtonAutomationPeer( someButton );
IInvokeProvider invokeProv =
  peer.GetPattern( PatternInterface.Invoke )
  as IInvokeProvider;
invokeProv.Invoke();

Taken from HERE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.